java内部窗体internalFrame的使用方法

来源:互联网 发布:自考和成考和网络教育 编辑:程序博客网 时间:2024/05/28 15:07
,运行的时候,先产生的是父窗体,里面有一个按钮

,点击他可以产生子窗体,生成的子窗体中也有一个按钮,点击这个按钮的时候,也将产生一个窗体,但

这个窗体是属于父窗体的,运行的时候可能你点击按钮后看不到效果,将窗体最大化在还原即可。(也就

是说刷新的工作没有完成)
父窗体文件:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class FrameTest extends JFrame implements ActionListener{
private JButton bn=new JButton( "this is a test ");
public FrameTest(){
super( "this is a test ");
this.setSize(500,500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container con=this.getContentPane();
FlowLayout fl=new FlowLayout();
con.setLayout(fl);
bn.addActionListener(this);
con.add(bn);
this.setContentPane(con);
this.setVisible(true);

}
public void actionPerformed(ActionEvent e){
InFrame subfrm=new InFrame();
this.getContentPane().add(subfrm);
}
public static void main(String[] args){
new FrameTest();
}
}
子窗体文件:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class InFrame extends JInternalFrame implements ActionListener{
UIManager.LookAndFeelInfo looks[];
private JButton bn=new JButton( "this is a test ");
public InFrame(){
super( "InFrame ");
looks=UIManager.getInstalledLookAndFeels();
try
{
UIManager.setLookAndFeel(looks[1].getClassName());
SwingUtilities.updateComponentTreeUI(this);
}
catch (Exception e)
{
e.printStackTrace();
}
this.setSize(500,500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container con=this.getContentPane();
FlowLayout fl=new FlowLayout();
con.setLayout(fl);
setLocation(200,150);
bn.addActionListener(this);
con.add(bn);
this.setContentPane(con);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e){
InFrame subfrm=new InFrame();
this.getParent().add(subfrm);
}
}