本帖最后由 2528870651 于 2014-4-29 19:51 编辑
- import java.awt.*;
- import java.awt.event.*;
- class WindowDemo
- {
- private Frame f;
- private Button b;
- private TextField tf;
- private TextArea ta;
- WindowDemo()
- {
- init();
- }
- public void init()
- {
- f = new Frame("my frame");
- f.setBounds(300,200,600,400);
- f.setLayout(new FlowLayout());
- b = new Button("转到");
- tf = new TextField(50);
- ta = new TextArea(10,50);
- f.add(tf);
- f.add(b);
- f.add(ta);
-
- myEvent();
- f.setVisible(true);
- }
- public void myEvent()
- {
- f.addWindowListener(new WindowAdapter()
- {
- public void windowClosing(WindowEvent e)
- {
- System.exit(0);
- }
-
- });
- b.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- //if(ta.getText() != null)//这里不加if的结果和加if的结果怎么不同,
- //一个是不管怎样先设为空,一个是如果不为空,则设为空。
- //可是,不加if的话,他会每点击鼠标两次才清空一次
- //加了if才正常。
- ta.setText("");
- String s = tf.getText();
-
- ta.append(s);
-
-
- }
- });
- }
- public static void main(String[] args)
- {
- new WindowDemo();
- }
- }
复制代码 |
|