⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jinternalframetest.java

📁 本java源程序包括了大量的学习程序(共27章)方便大家学习
💻 JAVA
字号:
package gui2;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class JInternalFrameTest extends JFrame implements ActionListener{
	private JMenuBar menuBar;
    private JMenuItem    newItem;
    private JDesktopPane desktopPane;               //用来管理JInternalFrame
    private int count = 1;
    
    public JInternalFrameTest() {
        super("JInternalFrame");
        setSize(350, 350); 
        //系统外观
        try {
        	UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch(Exception e) {
            System.err.println("Can't set look and feel: "+e);
        }
        //获取内容面板
        Container container = getContentPane();
        
        //建立菜单栏
    	menuBar  = new JMenuBar();
    	JMenu menu = new JMenu("文件");
    	newItem = new JMenuItem("新建");
    	newItem.addActionListener(this);
    	
    	//设置字体 
    	menu.setFont(new Font("Serif", Font.PLAIN, 12));
    	newItem.setFont(new Font("Serif", Font.PLAIN, 12));
    	
    	menu.add(newItem);
    	menuBar.add(menu);
    	
    	setJMenuBar(menuBar);
    	
        //创建JDesktopPane对象
        desktopPane = new JDesktopPane(); 
        desktopPane.setBackground(Color.WHITE);
        container.add(desktopPane); 

        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    
    //创建一个具有标题、可改变大小、可关闭、可最大化与最小化的JInternalFrame
    public void actionPerformed(ActionEvent event) {
        JInternalFrame internalFrame = new JInternalFrame(
                  "JInternalFrame " + (count++), true, true, true, true);  

        internalFrame.setLocation( 20,20);
        internalFrame.setSize(200,200); 
        internalFrame.setVisible(true);
  
        //获取JInternalFrame的内容窗格,用以加入新的组件。
        Container container = internalFrame.getContentPane();
        JTextArea textArea = new JTextArea();
        container.add(textArea);
        //将JInternalFrame加入JDesktopPane中
        desktopPane.add(internalFrame);  
        
        try {
            internalFrame.setSelected(true);
        } catch (java.beans.PropertyVetoException exception) {
          System.out.println("Exception while selecting");
        }
    }

    public static void main(String[] args) {
        JInternalFrameTest application = new JInternalFrameTest();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -