首页 > 其他 > 详细

GUI编程——弹窗

时间:2021-04-14 01:36:23      阅读:16      评论:0      收藏:0      [点我收藏+]

弹窗

JDialog , 用来被弹出,默认就有关闭事件!

 

 1 package com.kuang.lesson04;
 2 
 3 import javax.swing.*;
 4 import java.awt.*;
 5 import java.awt.event.ActionEvent;
 6 import java.awt.event.ActionListener;
 7 
 8 public class DialogDemo extends JFrame {
 9     public DialogDemo() {
10         this.setVisible(true);
11         this.setSize(700, 500);
12         this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
13 
14         //JFrame
15         Container container = this.getContentPane();
16         //绝对布局
17         container.setLayout(null);
18 
19         //按钮
20         JButton button = new JButton("点击弹出一个");
21         button.setBounds(30, 30, 200, 50);
22 
23         //点击这个按钮时,弹出一个弹窗
24         button.addActionListener(new ActionListener() {
25             @Override
26             public void actionPerformed(ActionEvent e) {
27                 //弹窗
28                 new MyDialogDemo();
29             }
30         });
31         container.add(button);
32     }
33         public static void main (String[] args){
34             new DialogDemo();
35         }
36     }
37 
38     //弹窗的窗口
39     class MyDialogDemo extends JDialog {
40         public MyDialogDemo() {
41             this.setVisible(true);
42             this.setBounds(100,100,500,500);
43             //this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
44 
45             Container container=this.getContentPane();
46             container.setLayout(null);
47 
48             container.add(new Label("欢迎学习Java!"));
49 
50         }
51     }

 

GUI编程——弹窗

原文:https://www.cnblogs.com/clblogs/p/14655452.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!