栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在ActionListener中退出方法

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在ActionListener中退出方法

基本上,您需要的是某种模式对话框,通过该对话框,您可以有效地在显示对话框的那一点上暂停程序的执行,直到关闭(关闭)该对话框为止,然后继续执行…

import java.awt.EventQueue;import java.awt.GridBagLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JDialog;import javax.swing.Jframe;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.SwingUtilities;import javax.swing.UIManager;import javax.swing.UnsupportedLookAndFeelException;public class Test {    public static void main(String[] args) {        new Test();    }    public Test() {        EventQueue.invokeLater(new Runnable() { @Override public void run() {     try {         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());     } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {         ex.printStackTrace();     }     JDialog dialog = new JDialog();     dialog.setTitle("Testing");     dialog.setDefaultCloseOperation(Jframe.DISPOSE_ON_CLOSE);     dialog.add(new TestPane());     dialog.pack();     dialog.setLocationRelativeTo(null);     dialog.setVisible(true);     System.out.println("Now back in the main..."); }        });    }    public class TestPane extends JPanel {        private JTextField field;        public TestPane() { setLayout(new GridBagLayout()); field = new JTextField(10); field.addActionListener(new ActionListener() {     @Override     public void actionPerformed(ActionEvent e) {         if ("exitsys".equals(field.getText())) {  SwingUtilities.getWindowAncestor(field).dispose();         }     } }); add(field);        }    }}

有关更多详细信息,请参见如何制作对话框



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/407271.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号