package GUITCP;
import java.awt.event.*;
import java.awt.*;
public class FrameDemo {
private Frame f;
private Button but;
private TextField tf;
private TextArea ta;
private Button but_1;
private Dialog dia;
FrameDemo(){
init();
}
private void init(){
//对组件进行初始化;
f=new Frame();
but=new Button();
tf=new TextField();
ta=new TextArea();
dia=new Dialog(f,"加油");
but_1=new Button();
//对组件进行设置。
f.setBounds(0,0,600,600);
tf.setColumns(50);
ta.setSize(300,200);
dia.setSize(200, 100);
//添加布局管理器;
f.setLayout(new FlowLayout());
//对窗体添加组件。
f.add(tf);
f.add(but);
f.add(ta);
f.add(but_1);
//f.add(dia);
f.setVisible(true);
myExent();
}
private void myExent(){
but.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String text=tf.getText();
ta.setText(text);
}
});
f.addWindowListener(new WindowAdapter(){
public void windowActived(){
}
public void windowClosing(WindowEvent e){
// System.exit(0);//关闭当前行的虚拟机;
f.dispose();
}
});
but_1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
dia.setVisible(true);
}
});
dia.addWindowListener(new WindowAdapter(){
public void windowClosed(WindowEvent e){
System.out.println("关了吗");//点击dialog的x按钮时并没有打印,那我要向关闭这个方法应该怎么写这个方法那。
System.exit(0);
dia.dispose();//关闭此窗口
}
});
}
public static void main(String[] ars){
new FrameDemo();
}
}
|