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