2
前propmt用戶確認退出我有這個類如何關閉的JFrame
package com.javacodegeeks.snippets.desktop;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
public class Main1 {
public static void main(String args[]) {
JFrame frame = new JFrame("Window Listener");
WindowListener listener = new WindowAdapter() {
public void windowClosing(WindowEvent w) {
int response = JOptionPane.showConfirmDialog(null, " Are you sure you want isuue the ticket?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (response == JOptionPane.YES_OPTION) {
System.exit(0);
}
}
};
frame.addWindowListener(listener);
frame.setSize(300, 300);
frame.setVisible(true);
}
}
我的問題是,如果用戶按下"No"
H/SE將不會再看到幀。 我希望用戶能夠回到主框架
我該如何做到這一點?