JDesktopPane类详解
来源:互联网 发布:下载听故事软件 编辑:程序博客网 时间:2024/06/14 22:24
1、先仔细阅读以下程序代码(JDesktopPane_1.java):
- package com.han;
- import java.awt.BorderLayout;
- import java.net.URL;
- import javax.swing.ImageIcon;
- import javax.swing.JDesktopPane;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- public class JDesktopPane_1 extends JFrame {
- /**
- *
- */
- private static final long serialVersionUID = 6415712755180575102L;
- public JDesktopPane_1() {
- // TODO Auto-generated constructor stub
- JDesktopPane desktopPane = new JDesktopPane();
- getContentPane().add(desktopPane, BorderLayout.CENTER);
- JLabel backLabel = new JLabel();
- // same as JDesktopPane_1.class.getResource()
- URL resource = this.getClass().getResource("/images/LightHouse.jpg");
- ImageIcon imageIcon = new ImageIcon(resource);
- backLabel.setIcon(imageIcon);
- // Very important ! because this is a virtual desktop and so one
- // should specify the position and the size of the component or
- // frame which are to placed on the desktop. Or else, the component
- // or the frame will not be displayed.
- backLabel.setBounds(0, 0, imageIcon.getIconWidth(),
- imageIcon.getIconHeight());
- // "new Integer(Integer.MIN_VALUE)" ensures that its layer is always under the others.
- desktopPane.add(backLabel, BorderLayout.CENTER, new Integer(Integer.MIN_VALUE));
- setBounds(0, 0, imageIcon.getIconWidth(), imageIcon.getIconHeight());
- }
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- JDesktopPane_1 frame = new JDesktopPane_1();
- frame.setTitle("系统桌面");
- frame.setVisible(true);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- }
2、再反复理解下面这段话:
用于创建多文档界面或虚拟桌面的容器。用户可创建 JInternalFrame
对象并将其添加到 JDesktopPane
。JDesktopPane
扩展了JLayeredPane
,以管理可能的重叠内部窗体。它还维护了对DesktopManager
实例的引用,这是由 UI 类为当前的外观 (L&F) 所设置的。注意,JDesktopPane
不支持边界。
此类通常用作 JInternalFrames
的父类,为 JInternalFrames
提供一个可插入的DesktopManager
对象。特定于 L&F 的实现 installUI
负责正确设置 desktopManager
变量。JInternalFrame
的父类是JDesktopPane
时,它应该将其大部分行为(关闭、调整大小等)委托给 desktopManager
。
有关此内容更多的文档和示例,请参阅 The Java Tutorial 的 How to Use Internal Frames 一节。
警告: Swing 不是线程安全的。有关更多信息,请参阅 Swing's Threading Policy。
警告:此类的序列化对象与以后的 Swing 版本不兼容。当前序列化支持适用于短期存储,或适用于在运行相同 Swing 版本的应用程序之间进行 RMI(Remote Method Invocation,远程方法调用)。从 1.4 版本开始,已在java.beans
包中添加了支持所有 JavaBeansTM 长期存储的功能。请参见java.beans.XMLEncoder
。
3、最后理解下面程序代码(JInternalFrameDemo1):
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class JInternalFrameDemo1 extends JFrame implements ActionListener{
- JDesktopPane desktopPane;
- int count = 1;
- public JInternalFrameDemo1(){
- super("JInternalFrameDemo1");
- Container contentPane = this.getContentPane();
- contentPane.setLayout(new BorderLayout());
- JButton button = new JButton("Crate New Internal Frames");
- button.addActionListener(this);
- contentPane.add(button,BorderLayout.SOUTH);
- desktopPane = new JDesktopPane();
- contentPane.add(desktopPane);//將虛擬桌面加入到content pane中
- this.setSize(new Dimension(300,300));
- this.setVisible(true);
- this.addWindowListener(new WindowAdapter(){
- @Override
- public void windowClosing(WindowEvent e){
- System.exit(0);
- }
- });
- }
- @Override
- public void actionPerformed(ActionEvent e){
- JInternalFrame internalFrame = new JInternalFrame("Internale Frame"+count++,true,true,true,true);
- //internalFrame.setLocation(20,20);
- internalFrame.setSize(new Dimension(200,200));
- internalFrame.setVisible(true);
- Container icontentPane = internalFrame.getContentPane();
- JTextArea textArea = new JTextArea();
- JButton b = new JButton("Internale Frame Button");
- icontentPane.add(textArea,"Center");
- icontentPane.add(b,"South");
- desktopPane.add(internalFrame);//將internalFrame加入到desktopPane,通過虛擬桌面來管理internalFrame
- //this.getContentPane().add(internalFrame);
- try{
- internalFrame.setSelected(true);//獲得焦點
- }catch(java.beans.PropertyVetoException ex){
- System.out.println("Exception while selecting");
- }
- }
- public static void main(String...args){
- new JInternalFrameDemo1();
- }
- }
- JDesktopPane类详解
- JDesktopPane
- JdesktopPane简介
- JDesktopPane 滚动条
- JDesktopPane加背景图片
- 设置JDesktopPane背景图片
- java 使用JDesktopPane
- 把JDesktopPane里面设置层
- JDesktopPane改变窗体大小时背景图片自动适应窗体大小
- java的JDesktopPane背景图片自适应窗口大小示例
- Volatile关键字详解,AtomicInteger类详解
- Php类详解
- ComboBox 类详解
- Java-util类详解
- CArchive 类详解
- phplib类中文详解
- UML类图详解
- UML类图详解
- Linux下进程间通信(小结)下
- Qt学习之路_10(Qt中statusBar,MessageBox和Timer的简单处理)
- Maven环境的快速搭建
- C#连接各种数据库语句(实例)
- arm linux上建立nfs文件系统
- JDesktopPane类详解
- 在Emacs中使用CEDET
- 工作札记--“ids for this class must be manually assigned before calling save”解决办法
- asp.net 创建Access数据库
- java-Service生命周期及用法! - 随心
- 内核中的 likely() 与 unlikely()
- oracle导入数据
- [转]C语言程序的存储区域
- HDOJ 1907