j_mdi.java.bak

来自「一个十分好的java基础学习的课件」· BAK 代码 · 共 77 行

BAK
77
字号
// ////////////////////////////////////////////////////////
// 
// J_MDI.java
// 
// Created by Jun-Hai Yong,    on XX xx, xxxx (Date)
// ////////////////////////////////////////////////////////
// Readme:
//      MDI(Multiple document interface) Example.
// ////////////////////////////////////////////////////////
// Using this example, please explicitly refer to the book:
//     Jun-Hai Yong. Programming in Java. 
//     Beijing: Tsinghua University Press, 2004.
// 使用本例子,请注明引用:
//     雍俊海. Java 程序设计. 北京: 清华大学出版社, 2004.
// Please note that the author and publisher make no 
// warranty of any kind on the examples provided.
// ////////////////////////////////////////////////////////

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

public class J_MDI extends JFrame
{

    private JDesktopPane m_desktop= new JDesktopPane( );
    private int m_count= 0;

    public J_MDI( )
    {
        super("MDI Example");
        JMenuBar  theMenuBar  = new JMenuBar( );
        JMenu     theMenuFile = new JMenu("File");
        JMenuItem theMenuItem = new JMenuItem("New");

        setJMenuBar(theMenuBar);
        theMenuBar.add(theMenuFile);
        theMenuFile.add(theMenuItem);
        theMenuFile.setMnemonic('F');
        theMenuItem.setMnemonic('N');

        Container theContainer= getContentPane( );
        theContainer.add(m_desktop);

        theMenuItem.addActionListener( new ActionListener( )
            {
                public void actionPerformed(ActionEvent e)
                {
                    String s= "Document " + m_count;
                    JInternalFrame theInternalFrame = new JInternalFrame( s, true, true, true, true );
                    m_count++;
                    J_Draw thePanel = new J_Draw( );
                    Container theInternalContainer = theInternalFrame.getContentPane( );
                    theInternalContainer.add( thePanel, BorderLayout.CENTER );
                    theInternalFrame.pack( );

                    m_desktop.add( theInternalFrame );
                    theInternalFrame.setVisible( true );
                } // End of method: actionPerformed
            } // End of the anonymous inner class, which implements ActionListener
        ); // End of invoking addActionListener
        
        setSize(400, 250);
        setVisible(true);
    } // End of constructor: J_MDI

    public static void main( String args[] )
    { 
        JFrame app = new J_MDI( );

        Container cp = app.getContentPane( );
        app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
    } // End of method: main

} // End of class: J_MDI

⌨️ 快捷键说明

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