package jsu;
//案例:
// MainUI是一个JFrame,点击JFrame中的按钮弹出模态的JDialog对象d1,
//点击d1中的按钮弹出JDialog对象d2,
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
//主窗口
class MainUI2 extends JFrame {
private JButton jb;// 窗体按钮
public MainUI2() {
jb = new JButton("弹出第1层JDialog对象d1");
this.setLayout(new FlowLayout());
this.setSize(300, 300);
this.add(jb);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
new D2(MainUI2.this);
}
});
this.setVisible(true);// 显示窗体
}
}
// 第1层JDialog
class D2 extends JDialog {
// final JDialog dialog;
private JTextField jt;
JButton jb;
JPanel jp;
public D2(JFrame jf) {
super(jf, "第1层Dialog");
jt = new JTextField("D1 对话框");
jb = new JButton("弹出2层JDialog");
JButton cancel = new JButton("取消");
this.setSize(200, 300);
this.setLayout(new FlowLayout());
this.add(jt);
this.add(jb);
this.add(cancel);
// this.setContentPane(jp);
this.setModal(true);// 模态
jb.addActionListener(new MyAc());
cancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
D2.this.dispose();
}
});
this.setVisible(true);// Dialog可见,是最后一条语句
}
private class MyAc implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
jt.setText("第1层Dialog");
new D3(D2.this, "第2层JDialog");
}
}
}
// 第2层JDialog
class D3 extends JDialog {
private JTextField jt;
JButton jb;
JPanel jp;
public D3(JDialog dialog, String title) {
super(dialog, title);
// this.setTitle("");
jp = new JPanel();// 把面板放置在JDialog
jt = new JTextField("第2层JDialog");
jb = new JButton("取消");
this.setSize(200, 300);
jp.setLayout(new FlowLayout());
jp.add(jt);
jp.add(jb);
this.setContentPane(jp);
this.setModal(true);
jb.addActionListener(new MyAc());
this.setVisible(true);// 最后一条语句
}
private class MyAc implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
D3.this.dispose();
}
}
}
//测试类
public class DemoY {
public static void main(String[] args) {
new MainUI2();
}
}
java多级模态窗口java多级模态窗口
需积分: 0 111 浏览量
2023-06-22
21:39:52
上传
评论
收藏 991B RAR 举报
君无戏言。
- 粉丝: 3272
- 资源: 27
最新资源
- JavaScript《基于自动分析数据并给出营业建议的餐厅管理系统(接入AI) 》+源代码+项目说明及资料
- 355670834783295707ad04e-427f-4cde-9589-e578224a8459.zip
- 动态sql解析引擎,类似mybatis动态sql的功能
- EDA365-Skill-V2.5安装包,支持Allegro17.x版本
- C# 常用单词汇总,常用单词汇总
- 【ERP标准流程-标准流程-库内业务管理】(DOC 14页).doc
- Python《数据库期末作业-餐厅点单系统 》+源代码+设计资料
- 学生成绩管理系统(C++课程设计
- 双指针法判断链表有环-go语言实现
- MyBatis动态SQL是一种强大的特性,它允许我们在SQL语句中根据条件动态地添加或删除某些部分,从而实现更加灵活和高效的数据
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈