请阅读到最后,我有3个问题。这是我的代码:
public class oncancel implements ActionListener {
public void actionPerformed(ActionEvent event) {
int confirm=JOptionPane.showConfirmDialog(null, "exit window ?",
"msgbox",JOptionPane.YES_NO_OPTION);
if(confirm==JOptionPane.YES_OPTION){
new graphic();
} //returns to the main frame
}
}
1)此代码出现2次但是它应该只出现一次??
2)当我选择是时,此代码会打开一个新窗口但是如果我想要保持在同一个窗口中,例如"返回到主页面" ??
3)此代码位于" x1"上课"取消"按钮。如果单击是,则应返回" x"类
有类似
的东西{
new graphic().x();
} ??
public class graphic {
...
xbutton.addActionListener(new x()); -->this one's in graphic
...
}
private class x implements ActionListener {
public void actionPerformed(ActionEvent event) {
...
x1button.addActionListener(new x1());
....
}}
public class x1 implements ActionListener {
public void actionPerformed(ActionEvent event) {
...
cancel.addActionListener(new oncancel());
...
}}
public class oncancel implements ActionListener {
public void actionPerformed(ActionEvent event) {
int confirm=JOptionPane.showConfirmDialog(null, "exit window?", "msg box", JOptionPane.YES_NO_OPTION);
if(confirm==JOptionPane.YES_OPTION) {
new graphic();
}
}
}