dialogexam.java
来自「Java程序设计实用教程源代码 本书源代码按章分别放置在不同的文件夹中,所有程」· Java 代码 · 共 52 行
JAVA
52 行
import java.awt.*;
import java.awt.event.*;
public class dialogExam {
Button btn1 = new Button("模态对话框");
Button btn2 = new Button("非模态对话框");
Frame frame = new Frame("TestDialog");
Panel panel = new Panel();
Button btn3 = new Button("确定");
Dialog dialog = new Dialog(frame, "Dialog Title", true);
FlowLayout flow = new FlowLayout();
dialogExam() {
panel.setLayout(new FlowLayout());
panel.setBackground(Color.PINK);
panel.add(btn1);
panel.add(btn2);
frame.setLayout(flow);
frame.add(panel);
btn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.setModal(true);
dialog.setTitle("模态对话框");
dialog.setVisible(true);
}
});
btn2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.setModal(false);
dialog.setTitle("非模态对话框");
dialog.setVisible(true);
}
});
frame.setBounds(0, 0, 400, 200);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
dialog.setLayout(flow);
dialog.add(btn3);
btn3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.dispose();
}
});
dialog.setBounds(0, 0, 200, 150);
}
public static void main(String args[]) {
new dialogExam();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?