java 为一个对话框中的按钮添加事件,以关闭该对话框,该事件怎么添加?
publicvoidAddSuccessDialogShow(){JDialogAddSuccessDialog=newJDialog(this,"添加成功!");JBu...
public void AddSuccessDialogShow()
{
JDialog AddSuccessDialog=new JDialog(this,"添加成功!");
JButton AddOkBt=new JButton("确定");
AddSuccessDialog.setBounds(450,200,220,150);
AddOkBt.setBounds(80,70,60,22);
AddSuccessDialog.setLayout(null);
AddSuccessDialog.add(AddOkBt);
AddSuccessDialog.show();
AddOkBt.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
AddSuccessDialog.dispose();//提示错误,什么原因??
}
});
} } 展开
{
JDialog AddSuccessDialog=new JDialog(this,"添加成功!");
JButton AddOkBt=new JButton("确定");
AddSuccessDialog.setBounds(450,200,220,150);
AddOkBt.setBounds(80,70,60,22);
AddSuccessDialog.setLayout(null);
AddSuccessDialog.add(AddOkBt);
AddSuccessDialog.show();
AddOkBt.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
AddSuccessDialog.dispose();//提示错误,什么原因??
}
});
} } 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询