java程序设计 清华出版社 孙燮华老师编写的程序源代码
源代码在线查看: windows.java
//windows.java
import java.awt.*;
import java.awt.event.*;
public class windows extends Frame implements ActionListener{
Button button1,button2;
demoframe window1;
public windows(String s){
super(s);
setLayout(new GridLayout(1,2));
button1=new Button("Show window");
button2=new Button("Hide window");
button1.addActionListener(this);
button2.addActionListener(this);
add(button1);
add(button2);
window1=new demoframe("Window Demo");
window1.setSize(200,100);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==button1){
window1.setVisible(true);
}
if(e.getSource()==button2){
//window1.setVisible(false);
window1.dispose();
}
}
public static void main(String args[]){
windows myWindows=new windows("My first windows");
myWindows.setSize(250,100);
myWindows.show();
}
}
class demoframe extends Frame{
Label label1;
demoframe(String title){
super(title);
setLayout(new GridLayout(1,1));
label1=new Label("Hello from Java!");
add(label1);
}
}