Swing中JInternalFrame的使用

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class JInternalFrame1 extends JFrame implements ActionListener{
JDesktopPane desktopPane;
int count = 1;
public JInternalFrame1() {
super("JInternalFrame1");}
Container contentPane = this.getContentPane();
contentPane.setLayout(new BorderLayout());
JButton b = new JButton("Create New Internal Frames");
b.addActionListener(this);        //注册按钮监听器
contentPane.add(b, BorderLayout.SOUTH);
desktopPane = new JDesktopPane(); //建立一个desktopPane
contentPane.add(desktopPane);     //加入到contentPane中
setSize(350, 350);
show();
addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);}});}
public void actionPerformed(ActionEvent e) {
JInternalFrame internalFrame = new JInternalFrame( "Internal Frame "+(count++), true, true, true, true);  //还是自己看API吧。(如何构造?)
internalFrame.setLocation( 20, 20);
internalFrame.setSize(200, 200);
internalFrame.setVisible(true);
Container icontentPane = internalFrame.getContentPane(); //用来加入新组件,(正如我们开始看的那样,Swing都这样的)JTextArea textArea = new JTextArea();   JButton b = new JButton("Internal Frame Button");
icontentPane.add(textArea,"Center");
icontentPane.add(b,"South");
desktopPane.add(internalFrame);//将internalFrame加入到desktopPane中。如此以来,即使产生很多的internalFrame ,desktopPane也能把他们的层次关系管理的相当良好。
try {internalFrame.setSelected(true);
} catch (java.beans.PropertyVetoException ex) {System.out.println("Exception while selecting");}}

public static void main(String[] args){new JInternalFrame1();}}
/****************************************************JInternalFrame和JFrame是几乎一样的,唯一不同的是JInternalFrame是lightweight(轻量级)的。它不能单独出现必须依附于最上层的组件上,呵呵,他能利用JAVA提供的LOOK and Feel的功能作出不同于操作系统的窗口外型,比JFrame更具弹性。****************************************************** */


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值