dialogdemo.txt
来自「JAVA的一些基础教程」· 文本 代码 · 共 68 行
TXT
68 行
1: import java.awt.*;
2: import java.awt.event.*;
3:
4: public class DialogDemo extends Frame
5: implements ActionListener
6: {
7: Button btnExit;
8: Button btnYes;
9: Button btnNo;
10: Dialog dlgConfirm;
11:
12: public DialogDemo()
13: {
14: btnExit = new Button("退出");
15: btnExit.addActionListener(this);
16:
17: add(btnExit);
18: setLayout(new FlowLayout());
19:
20: dlgConfirm = new Dialog(this);
21: dlgConfirm.setResizable(false);
22:
23: btnYes = new Button("是");
24: btnYes.addActionListener(this);
25:
26: btnNo = new Button("否");
27: btnNo.addActionListener(this);
28:
29: dlgConfirm.add(btnYes);
30: dlgConfirm.add(btnNo);
31: dlgConfirm.setTitle("确定退出?");
32:
33: dlgConfirm.setSize(200, 100);
34: dlgConfirm.setLayout(new FlowLayout());
35:
36: addWindowListener(new WinCloser());
37: setTitle("Using a Dialog");
38: setBounds( 100, 100, 300, 300);
39: setVisible(true);
40:
41: }
42:
43:
44: public void actionPerformed(ActionEvent ae)
45: {
46: if (ae.getActionCommand().equals("退出"))
47: dlgConfirm.show();
48: if (ae.getActionCommand().equals("是"))
49: System.exit(0);
50: if (ae.getActionCommand().equals("否"))
51: dlgConfirm.setVisible(false);
52: }
53:
54: public static void main(String[] args)
55: {
56: DialogDemo td = new DialogDemo();
57: }
58:
59: }
60:
61: class WinCloser extends WindowAdapter
62: {
63: public void windowClosing(WindowEvent e)
64: {
65: System.exit(0);
66: }
67: }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?