弹窗(Dialog)的使用

弹窗窗口的建立:

复制代码
 1 //弹窗的窗口
 2 class MyDialogDemo extends JDialog{
 3     public MyDialogDemo() {
 4         this.setVisible(true);
 5         this.setBounds(100,100,500,500);
 6         this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
 7         
 8         Container container = this.getContentPane();
 9         container.setLayout(null);
10         
11         container.add(new Label("1234"));
12     }
13 }
复制代码

 

 

复制代码
 1 //主窗口
 2 public class DialogDemo extends JFrame {
 3     public static void main(String[] args) {
 4         new DialogDemo();
 5     }
 6     
 7     public DialogDemo() {
 8         this.setVisible(true);
 9         this.setSize(700,500);
10         this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
11         
12         //JFrame 放东西,容器
13         Container container = this.getContentPane();
14         //绝对布局
15         container.setLayout(null);
16         
17         //按钮
18         JButton button = new JButton("点击弹出一个对话框");
19         button.setBounds(30,30,200,50);
20         
21         //点击这个按钮时候,弹出一个弹窗
22         button.addActionListener(new ActionListener() {
23             public void actionPerformed(ActionEvent e) {
24                 new MyDialogDemo();
25             }
26         });
27         
28         container.add(button);
29     }
30 }
复制代码

 

posted @   jue1e0  阅读(213)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
点击右上角即可分享
微信分享提示