📄 testjdialog.java
字号:
/* * 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -