this.addWindowListener....private class SymWindow extends java.awt.event.WindowAdapter {
public void windowClosing(java.awt.event.WindowEvent event) {
Object object = event.getSource();
Job_windowClosing(event);
} void Job_windowClosing(java.awt.event.WindowEvent event) {
exitApplication();
}
}private void exitApplication() {
try {
// Show a confirmation dialog
int reply = JOptionPane.showConfirmDialog(.......);
// If the confirmation was affirmative, handle exiting.
if (reply == JOptionPane.YES_OPTION) {
this.dispose(); // free the system resources
System.exit(0); // close the application
}
}
catch (Exception e) {
e.printStackTrace();
}
}
public void windowClosing(java.awt.event.WindowEvent event) {
Object object = event.getSource();
Job_windowClosing(event);
} void Job_windowClosing(java.awt.event.WindowEvent event) {
exitApplication();
}
}private void exitApplication() {
try {
// Show a confirmation dialog
int reply = JOptionPane.showConfirmDialog(.......);
// If the confirmation was affirmative, handle exiting.
if (reply == JOptionPane.YES_OPTION) {
this.dispose(); // free the system resources
System.exit(0); // close the application
}
}
catch (Exception e) {
e.printStackTrace();
}
}
this.addWindowListener....这句我不太明白,
我将你的代码加到我的Application.java中,但是不能实现,能不能说具体点啊???
实在不好意思,上面的代码应该加到哪里啊?我分别加在"Application.java"和"MyFrame.java"中时, this.dispose(); //这句话都会出错
而且退出应用程序时并没有响应.还请你多多指教啊????
我想在FrameMain 中应该添加一个jframe.addWindowListener(new SymWindow());
方法,请问该方法形式应该是什么样的???
public class AppSuperEditor {
FrameMain frame = new FrameMain();
public AppSuperEditor() {
if (packFrame) {
frame.pack();
}
else {
frame.validate();
}
frame.setVisible(true);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setResizable(false);
jframe.addWindowListener(new SymWindow()); }
private void exitApplication() {
try {
String strMessage = "Are you sure to close";
int reply = JOptionPane.showConfirmDialog(null,strMessage);
if (reply == JOptionPane.YES_OPTION) {
frame.dispose(); // free the system resources
System.exit(0); // close the application
}
}
catch (Exception e) {
e.printStackTrace();
}
} //Main method
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
AppSuperEditor app = new AppSuperEditor();
}
catch(Exception e) {
e.printStackTrace();
}
}
//==========================================================
private class SymWindow extends java.awt.event.WindowAdapter {
public void windowClosing(java.awt.event.WindowEvent event) {
Object object = event.getSource();
Job_windowClosing(event);
}
void Job_windowClosing(java.awt.event.WindowEvent event) {
exitApplication();
}
}
}
public void windowClosing(WindowEvent e) {
result=JOptionPane.showConfirmDialog(f,"是否退出出?","提示",JOptionPane.INFORMATION_MESSAGE);
if (result==0)
{
cancel();
}
if (result=1){
frame.setVisable(false);
System.exit(0);
}
}
});