JInternalFrame的一个实例

本文介绍了一个使用Java Swing创建Internal Frame的示例程序。通过在JFrame中嵌套JDesktopPane来展示可移动、可关闭的内部窗口。文章提供了完整的源代码及说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

public class inFrame extends JFrame implements ActionListener{ //建立一个Frame窗体
 
 private JButton button;
 private JDesktopPane desktop; //用来存放internalFrame的容器
 
 public inFrame(){ //用构造函数,初始化
  //有些人在做INTERNALFRAME时,internalFrame会无法显示,其主要原因是窗口界面重叠覆盖所造成的啊
  //我现在在contentpane上面 加了两个 容器,一个是desktop用来存放JInternalFrame的
           // 另一个是panel用来存放button的,
  //然后把他们的位置错开,这个就不会覆盖了啊
  super("InternalFrame的一个例子");
  this.setSize(800,600);
  this.setLocation(100,80);
  this.setLayout(null);
  
  desktop=new JDesktopPane();
  desktop.setLayout(null);
  desktop.setBounds(0,100,800,500);
  this.getContentPane().add(desktop);
  init();
  
  this.setVisible(true);
 }
 
 private void init(){ //添加按钮,并且给按钮增加 监听
  button=new JButton("打开InternalFrame");
  button.setBounds(300,25,200,40);
  button.addActionListener(this);
  
  JPanel panel = new JPanel();
  panel.setLayout(null);
  panel.setBounds(0,0,800,100);
  panel.add(button);
  this.getContentPane().add(panel);
  
 }
 
 public void actionPerformed(ActionEvent e){ //事件处理
  JInternalFrame inframe =new JInternalFrame("我是internalFrame",true,true,true,true);//定义一个inframe
  inframe.setSize(600,400);
  inframe.setLocation(50,50);
  
  desktop.add(inframe);//将inframe添加到desktop中
  inframe.setVisible(true);//使他显示
 }
 
 public static void main (String args[]){
  new inFrame(); 
 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值