|
我有下面一段程序,想请教按“确定”退出按钮关闭以下a1,c1两个框?
package b3;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
public class b3 extends JFrame implements ActionListener
{ JFrame a1=new JFrame();
JButton b1;
b3()
{
b1=new JButton("a");
add(b1);
b1.addActionListener(this);
setBounds(300,100,400,300);
setResizable(false);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
new f01();
}
}
public static void main(String args[])
{
new b3();
}
}
class f01 extends JFrame implements ActionListener
{ JFrame c1=new JFrame();
Box baseBox,boxV1,boxV2;
Button a= new Button(" 是 ");
Button b=new Button(" 否 ");
CardLayout cardlayout=new CardLayout();
f01()
{ super("aa");
Panel p1=new Panel();
boxV1=Box.createVerticalBox();
boxV1.add(Box.createVerticalStrut(40));
boxV1.add(new Label("确定要退出么?"));
boxV1.add(Box.createVerticalStrut(20));
baseBox=Box.createHorizontalBox();
baseBox.add(Box.createHorizontalStrut(40));
baseBox.add(boxV1);
baseBox.add(Box.createHorizontalStrut(20));
add(baseBox);
p1.add(a);
p1.add(b);
a.addActionListener(this);
b.addActionListener(this);
add(p1,BorderLayout.SOUTH);
setBounds(400,200,200,150);
setResizable(false);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==a)
{
a1.dispose();
c1.dispose(); //这个步骤不知道出错在哪里,请教
是不是ActionListener的问题?
不知道怎么修改
}
else if(e.getSource()==b)
{
dispose();
}
}
} |
|