Chinaunix首页 | 论坛 | 博客
  • 博客访问: 542572
  • 博文数量: 855
  • 博客积分: 40000
  • 博客等级: 大将
  • 技术积分: 5005
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-16 19:08
文章分类

全部博文(855)

文章存档

2011年(1)

2008年(854)

我的朋友

分类:

2008-10-16 19:19:18

    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更具弹性。
*******************************************************/

【责编:landy】

--------------------next---------------------

阅读(299) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~