testjdialog.java

来自「java2 primer plus一书源程序」· Java 代码 · 共 73 行

JAVA
73
字号
/* * TestJDialog.java * * Created on July 30, 2002, 2:36 PM */package ch16;import javax.swing.*;import java.awt.*;import java.awt.event.*;/** * * @author  Stephen Potts * @version */public class TestJDialog extends JFrame implements ActionListener{    JButton btnExit;    JButton btnYes;    JButton btnNo;    JDialog dlgConfirm;        /** Creates new TestJDialog */    public TestJDialog()    {        btnExit = new JButton("Exit");        btnExit.addActionListener(this);                getContentPane().add(btnExit);        this.getContentPane().setLayout(new FlowLayout());                dlgConfirm = new JDialog(this);        dlgConfirm.setResizable(false);                btnYes = new JButton("Yes");        btnYes.addActionListener(this);                btnNo = new JButton("No");        btnNo.addActionListener(this);                dlgConfirm.getContentPane().add(btnYes);        dlgConfirm.getContentPane().add(btnNo);        dlgConfirm.setTitle("Are you sure?");                dlgConfirm.setSize(200, 100);        dlgConfirm.getContentPane().setLayout(new FlowLayout());                this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        setTitle("Using a JDialog");        setBounds( 100, 100, 300, 300);        setVisible(true);            }        public void actionPerformed(ActionEvent ae)    {        if (ae.getActionCommand().equals("Exit"))            dlgConfirm.show();        if (ae.getActionCommand().equals("Yes"))            System.exit(0);        if (ae.getActionCommand().equals("No"))            dlgConfirm.setVisible(false);    }        public static void main(String[] args)    {        TestJDialog td = new TestJDialog();    }    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?