dialog extends JDialog {
JButton btn = new JButton();
...
btn_actionperformed(ActionEvent e) {
this.setVisible(false); //this.dispose() also ok.
}
}
JButton btn = new JButton();
...
btn_actionperformed(ActionEvent e) {
this.setVisible(false); //this.dispose() also ok.
}
}
public class winFrmHelpAbout extends JDialog implements ActionListener{
JButton jbOK=new JButton("确定(O)");
jbOK.addActionListener(this);
getContentPane().add(jbOK); public void actionPerformed(ActionEvent ae) {
if(ae.getActionCommand()=="确定(O)"){
this.dispose();
}
}}当然和我原来预想的简洁的代码(不用额外写一个类)不一样,可见要得到“如何在单独的函数的生成按钮的事件中得到上层JDialog的指针从而关闭它”得想法是不可能实现了。(如果能实现,我额外加分!)结了吧,谢谢各位。