- import java.awt.*;
- import java.awt.event.*;
- class Mywindow
- {
- private Frame f;
- private Button but;
- private TextField tf;//单行的文本
- private TextArea ta;//多行的文本
-
-
- Mywindow()
- {
- into();
- }
- public void into()
- {
- //创建一个 窗口
- f =new Frame("我的");
- //设计大小,布局
- f.setLayout(new FlowLayout());
- f.setBounds(300,200,500,400);
-
- //添加组件
- but=new Button("转到");
- tf =new TextField(20);
- ta =new TextArea(20,40);
- f.add(tf);
- f.add(but);
- f.add(ta);
-
-
- //添加事件
- Myevent();
-
- //让窗口显示
- f.setVisible(true);
- }
- private void Myevent()
- {
-
- but.addActionListener(new ActionListener()
- {
- public void actionPerformad(ActionEvent e)
- {
- String text =tf.getText();
- System.out.println(text);
-
- }
- });
-
- f.addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent e)
- {
- System.exit(0);
- //System.out.println("guanbi");
- }
- });
- }
- public static void main(String[] args)
- {
- new Mywindow();
- }
- }
复制代码 |