📄 jdialogdemo.java
字号:
package chapter6.component;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JDialogDemo extends JFrame implements ActionListener {
public JDialogDemo() {
Container contentPane = this.getContentPane();
JButton jButton1 = new JButton("显示对话框");
jButton1.addActionListener(this);
contentPane.add(jButton1);
this.setTitle("JDialogDemo");
this.setSize(300, 300);
this.setLocation(400,400);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("显示对话框")) {
HelloDialog hw = new HelloDialog(this);
}
}
class HelloDialog implements ActionListener {
JDialog jDialog1 = null;
HelloDialog(JFrame jFrame) {
jDialog1 = new JDialog(jFrame, "Dialog", true);
JButton jButton1 = new JButton("关闭");
jButton1.addActionListener(this);
jDialog1.getContentPane().add(jButton1);
jDialog1.setSize(80,80);
jDialog1.setLocation(450,450);
jDialog1.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("关闭")) {
//jDialog1.setVisible(false);
jDialog1.dispose();
}
}
}
public static void main(String[] args) {
JDialogDemo test = new JDialogDemo();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -