📄 mdiapplicationdemo.java
字号:
//MdiApplicationDemo.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MdiApplicationDemo extends JFrame implements ActionListener
{
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();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -