jdialogdemo.java
来自「精通JBuilder2006 源代码 精通JBuilder2006 源代码」· Java 代码 · 共 50 行
JAVA
50 行
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 + =
减小字号Ctrl + -
显示快捷键?