/*
对frame进行设置查看属性
*/
package en.itcast.java.tools;
import java.awt.*;
import java.awt.Event.*;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import javax.naming.InitialContext;
public class FrameDemo {
private Frame f;
private Button b;
public FrameDemo() {
init();
}
public void init()
{
f= new Frame();
//b=new Button();
f.setBounds(400,300,200,300);
f.setVisible(true);
f.setLayout(new FlowLayout());
b=new Button("按钮");
f.add(b);
myEvent();
}
private void myEvent()
{
f.addWindowListener(new WindowAdapter() {
public void widowClosing()
{
System.exit(0);
}
});
b.addActionListener(new ActionListener()
{
private int count =1;
public void actionProformed(ActionEvent e)
{
Button b1=(Button)e.getSource();
Frame f1=(Frame)b1.getParent();
//获得指定子窗口的父窗口的句柄,但是这里是一个button那?
f1.add(new Button("button-"+count++));
f1.validate();//生效,使合法化批准
}
}
);
}
public static void main(String[] args) {
new FrameDemo();
}
}
|