我点击这个确定按钮时窗口无法关闭而且报错?
//这是子类:public class pannel2 extends JFrame {
private static final long serialVersionUID = 1L;
private String title = "帮助文档";
Container con = getContentPane();
JButton button_sure = new JButton("确定");
// private JFrame f=new JFrame();
private JTextArea textArea = new JTextArea(20, 40);
private Box vbox = Box.createVerticalBox();
private Box hbox1 = Box.createHorizontalBox();
private Box hbox2 = Box.createHorizontalBox();
private int HEIGHT = 400;
private int WIDTH = 600;
@SuppressWarnings("deprecation")
public pannel2() throws Exception {
this.setSize(WIDTH, HEIGHT);
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
int HEIGHT1 = screenSize.height;
int WIDTH1 = screenSize.width;
int X = (WIDTH1 - WIDTH) / 2 - 100;
int Y = (HEIGHT1 - HEIGHT) / 2 - 100;
this.setTitle(title);
this.setSize(WIDTH, HEIGHT);
this.setSize(WIDTH, HEIGHT);
this.setLocation(X, Y);
this.setResizable(false);
this.setTitle(title);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setOpacity((float) 0.85);
this.setBackground(Color.YELLOW);
textArea.setLineWrap(true);
textArea.setEditable(false);
textArea.setOpaque(true);
hbox1.add(textArea);
hbox2.add(button_sure);
vbox.add(hbox1);
vbox.add(Box.createVerticalStrut(2));
vbox.add(hbox2);
con.add(vbox, BorderLayout.CENTER);
button_sure.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent a) {
// TODO Auto-generated method stub
if (button_sure == a.getSource()) {
((JFrame)a.getSource()).dispose();//错误在这,但我不会改求帮助
}
}
});
this.pack();
this.show();
}
}
//mian函数
public class pannel2test {
public static void main(String[] args) throws Exception {
pannel2 p2 =new pannel2();
}
}
帮我看看因该如何修改呢?