import javax.swing.*;import java.awt.*;import java.awt.event.*;public class Closingframe extends Jframe { private JMenuBar MenuBar = new JMenuBar(); private Jframe frame = new Jframe(); private static final long serialVersionUID = 1L; private JMenu File = new JMenu("File"); private JMenuItem Exit = new JMenuItem("Exit"); public Closingframe() { File.add(Exit); MenuBar.add(File); Exit.addActionListener(new ExitListener()); WindowListener exitListener = new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { int confirm = JOptionPane.showOptionDialog(frame, "Are You Sure to Close this Application?", "Exit /confirm/iation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (confirm == JOptionPane.YES_OPTION) { System.exit(0); } } }; frame.addWindowListener(exitListener); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.setJMenuBar(MenuBar); frame.setPreferredSize(new Dimension(400, 300)); frame.setLocation(100, 100); frame.pack(); frame.setVisible(true); } private class ExitListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { int confirm = JOptionPane.showOptionDialog(frame, "Are You Sure to Close this Application?", "Exit /confirm/iation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (confirm == JOptionPane.YES_OPTION) { System.exit(0); } } } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Closingframe cf = new Closingframe(); } }); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)