基本的Java Swing,如何退出和处置您的应用程序 JFrame

基本的Java Swing,如何退出和处置您的应用程序 JFrame,第1张

基本的Java Swing,如何退出处置您的应用程序/ JFrame
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(); }        });    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5479201.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存