当前位置: 技术问答>java相关
大家帮忙看看这段代码问题出在那?怎么总是出现异常而无法关闭对话框呀??
来源: 互联网 发布时间:2015-05-05
本文导语: public class Question extends JFrame implements ActionListener {//////b1 is a button b1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { if(flag == 0){ addQuestion aq = new addQuesti...
public class Question extends JFrame implements ActionListener
{//////b1 is a button
b1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) {
if(flag == 0){
addQuestion aq = new addQuestion(); flag = 1;
}
}
});
}
class addQuestion extends JApplet //implements ActionListener
{
Question mf;
private JDialog dialog = new JDialog();
addQuestion()
{
dialog.setBounds(0,0,400,400);
dialog.show();
Container dContentPane = dialog.getContentPane();
dContentPane.setLayout(null);
Button button1 = new Button("Test");
dContentPane.add(button1);
dialog.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
mf.flag = 0;
dialog.dispose(); }
});
}
}
{//////b1 is a button
b1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) {
if(flag == 0){
addQuestion aq = new addQuestion(); flag = 1;
}
}
});
}
class addQuestion extends JApplet //implements ActionListener
{
Question mf;
private JDialog dialog = new JDialog();
addQuestion()
{
dialog.setBounds(0,0,400,400);
dialog.show();
Container dContentPane = dialog.getContentPane();
dContentPane.setLayout(null);
Button button1 = new Button("Test");
dContentPane.add(button1);
dialog.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
mf.flag = 0;
dialog.dispose(); }
});
}
}
|
请把dialog.show();放到最下面