java内部窗体internalFrame的使用方法

,运行的时候,先产生的是父窗体,里面有一个按钮

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

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

是说刷新的工作没有完成)
父窗体文件:
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);
}
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值