JDiolog弹窗
### 3.2弹窗
```java
package com.zishi.lesson04;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
//主窗口
public class DialogDemo extends JFrame {
public DialogDemo() {
this.setVisible(true);
this.setSize(700,500);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
//JFrame 放东西,容器
Container container = this.getContentPane();
//绝对布局
container.setLayout(null);
//按钮
JButton button = new JButton("点击弹出对话框");
button.setBounds(30,30,200,50);
//点击这个按钮的时候弹出弹窗,监听事件
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//弹窗
new MyDialogDemo();
}
});
container.add(button);
}
public static void main(String[] args) {
new DialogDemo();
}
}
//弹窗的窗口
class MyDialogDemo extends JDialog{
public MyDialogDemo() {
this.setVisible(true);
this.setBounds(100,100,500,500);
//this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 已经有这个方法
Container container = this.getContentPane();
container.setLayout(null); //设置了绝对布局,label标签不显示
container.add(new Label("弹窗"));
container.setBounds(100,100,200,200);
}
}
```