JInternalFrame创建内部窗体

package Assis;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class MdiApplicationDemo extends JFrame implements ActionListener {
	private static final long serialVersionUID = 1L;
	JButton b = new JButton("创建内部窗体 ");
	JDesktopPane desktopPane = new JDesktopPane();
	int windowCount = 1;

	public MdiApplicationDemo() {
		// 获取内容窗格容器
		Container contentPane = getContentPane();
		// 创建功能按钮面板
		JPanel pnlControlPane = new JPanel();
		pnlControlPane.add(b);
		// 设置桌面窗体的布局管理为FlowLayout,缺省为null
		desktopPane.setLayout(new FlowLayout());
		// 添加事件监听器
		b.addActionListener(this);
		// 把功能按钮面板和桌面窗体加入到内容窗格容器中
		contentPane.add(pnlControlPane, BorderLayout.NORTH);
		contentPane.add(desktopPane, BorderLayout.CENTER);
	}

	// 程序的入口方法
	public static void main(String[] args) {
		MdiApplicationDemo frame = new MdiApplicationDemo();
		// 设置框架窗体的事件监听(关闭窗体事件)
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		// 显示框架窗体
		frame.setSize(600, 400);
		frame.setVisible(true);
	}

	// 处理创建内部窗体按钮事件
	public void actionPerformed(ActionEvent event) {
		// 创建一个新的内部窗体
		JInternalFrame jif = new JInternalFrame("内部窗体[" + windowCount++ + "]", // title
				true, // resizable
				true, // closable
				true, // maximizable
				true); // iconifiable
		// 设置内部窗体大小为250×100
		jif.setPreferredSize(new Dimension(250, 100));
		// 把内部窗体加入到桌面窗体中
		desktopPane.add(jif);
		// 刷新
		desktopPane.revalidate();
		jif.setVisible(true);
	}
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值