import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class jdesktoppane extends JFrame{
public jdesktoppane() {
super();
setTitle("桌面面板和内部窗体");
setBounds(100, 100, 400, 300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
Container c = getContentPane();
JDesktopPane desk = new JDesktopPane();
c.add(desk,BorderLayout.CENTER);
JPanel jp = new JPanel();
jp.setLayout(new FlowLayout(0));
c.add(jp, BorderLayout.NORTH);
JButton jb1 = new JButton("天");
JButton jb2 = new JButton("地");
JButton jb3 = new JButton("人");
jp.add(jb1);
jp.add(jb2);
jp.add(jb3);
jb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JInternalFrame inframe = new JInternalFrame();
desk.add(inframe);
inframe.setBounds(10, 10, 200, 100);
inframe.setTitle("内部窗体1");
inframe.setVisible(true);
inframe.setResizable(true);
inframe.setClosable(true);
inframe.setMaximizable(true);
inframe.setIconifiable(true);
}
});
jb2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JInternalFrame inframe1 = new JInternalFrame("内部窗体2",true,true,true,true);
inframe1.setBounds(20,20,200,100);
inframe1.setVisible(true);
desk.add(inframe1);
}
});
jb3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JInternalFrame inframe2 = new JInternalFrame("内部窗体3",true,true,true,true);
inframe2.setBounds(30,30,200,100);
inframe2.setVisible(true);
desk.add(inframe2);
}
});
}
public static void main(String[] args) {
new jdesktoppane();
}
}