import java.awt.*;
import java.awt.event.*;
class EventText
{
private Frame f;
private Button but;
private TextField tf;
private TextArea ta;
EventText(){
show();
}
public void show(){
f=new Frame("你好");
f.setBounds(300,100,500,400);
f.setLayout(new FlowLayout());
tf=new TextField(30);
but=new Button("转到");
ta=new TextArea(50,60);
f.add(tf);
f.add(but);
f.add(ta);
method();
f.setVisible(true);
}
public void method(){
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.out.println("关闭");
System.exit(0);
}
});
but.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String text=tf.getText();
ta.setText(text);
ta.setText("");
}
});
}
}
class EventTextDemo
{
public static void main(String[] args)
{
new EventText();
}
} |
|