packagenoname;importjava.awt.*;importjava.awt.event.*;publicclassmainprogramextendsFrameimplementsActionListener,WindowListener{inti;Buttonb1=newButton("确定");Buttonb2=n...
package noname;
import java.awt.*;
import java.awt.event.*;
public class mainprogram extends Frame implements ActionListener,WindowListener
{
int i;
Button b1 = new Button("确定");
Button b2 = new Button("关闭");
void FlowLayoutEX()
{
this.setTitle("布局管理器");
this.setLayout(new FlowLayout());
this.add(b1);
b1.addActionListener(this);
this.add(b2);
b2.addActionListener(this);
this.addWindowListener(this);
this.setBounds(100, 100, 250, 250);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
i++;
Button bi = new Button("按钮"+i);
this.add(bi);
this.show(true);
}
public void windowClosing(WindowEvent f)
{
System.exit(0);
}
public void windowOpened(WindowEvent f){}
public void windowClosed(WindowEvent f){}
public void windowIconified(WindowEvent f){}
public void windowDeiconified(WindowEvent f){}
public void windowActivated(WindowEvent f){}
public void windowDeactivated(WindowEvent f){}
public static void main(String args[])
{
mainprogram window = new mainprogram();
window.FlowLayoutEX();
}
}
这里面的b1已经设置了监听,如何把b2设置为关闭窗口的按钮
展开