GUI_菜单练习

package com.mywindow.test;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;



import javax.swing.JDialog;

import javax.swing.JFileChooser;

import javax.swing.JMenu;

import javax.swing.JMenuBar;

import javax.swing.JMenuItem;

import javax.swing.WindowConstants;

import javax.swing.SwingUtilities;





/**

* This code was edited or generated using CloudGarden's Jigloo

* SWT/Swing GUI Builder, which is free for non-commercial

* use. If Jigloo is being used commercially (ie, by a corporation,

* company or business for any purpose whatever) then you

* should purchase a license for each developer using Jigloo.

* Please visit www.cloudgarden.com for details.

* Use of Jigloo implies acceptance of these licensing terms.

* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR

* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED

* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.

*/

public class MyMenu extends javax.swing.JFrame {

    private JMenuBar jMenuBar1;

    private JMenu jMenu5;

    private JMenuItem jMenuItem3;

    private JMenuItem jMenuItem2;

    private JMenuItem jMenuItem1;

    private JMenu jMenu6;

    private JMenu jMenu4;

    private JMenu jMenu3;

    private JMenu jMenu2;

    private JMenu jMenu1;

    //private JFileChooser chooser;

    private JDialog dialog;

    /**

    * Auto-generated main method to display this JFrame

    */

    public static void main(String[] args) {

        SwingUtilities.invokeLater(new Runnable() {

            public void run() {

                MyMenu inst = new MyMenu();

                inst.setLocationRelativeTo(null);

                inst.setVisible(true);

            }

        });

    }

    

    public MyMenu() {

        super();

        initGUI();

    }

    

    private void initGUI() {

        try {

            setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

            {

                jMenuBar1 = new JMenuBar();

                setJMenuBar(jMenuBar1);

                {

                    jMenu1 = new JMenu();

                    jMenuBar1.add(jMenu1);

                }

                {

                    jMenu2 = new JMenu();

                    jMenuBar1.add(jMenu2);

                    jMenu2.setText("\u6587\u4ef6");

                    {

                        jMenuItem1 = new JMenuItem();

                        jMenu2.add(jMenuItem1);

                        jMenuItem1.setText("\u6253\u5f00");

                        jMenuItem1.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent evt) {

                                jMenuItem1ActionPerformed(evt);

                            }

                        });

                    }

                }

                {

                    jMenu3 = new JMenu();

                    jMenuBar1.add(jMenu3);

                    jMenu3.setText("\u7f16\u8f91");

                    {

                        jMenuItem2 = new JMenuItem();

                        jMenu3.add(jMenuItem2);

                        jMenuItem2.setText("\u590d\u5236");

                    }

                    {

                        jMenuItem3 = new JMenuItem();

                        jMenu3.add(jMenuItem3);

                        jMenuItem3.setText("\u526a\u5207");

                    }

                }

                {

                    jMenu4 = new JMenu();

                    jMenuBar1.add(jMenu4);

                    jMenu4.setText("\u67e5\u770b");

                }

                {

                    jMenu5 = new JMenu();

                    jMenuBar1.add(jMenu5);

                    jMenu5.setText("\u5de5\u5177");

                }

                {

                    jMenu6 = new JMenu();

                    jMenuBar1.add(jMenu6);

                    jMenu6.setText("\u5e2e\u52a9");

                }

            }

            pack();

            setSize(400, 300);

        } catch (Exception e) {

            //add your error handling code here

            e.printStackTrace();

        }

    }

    

    private void jMenuItem1ActionPerformed(ActionEvent evt) {

        dialog = new JDialog(this);

        dialog.setVisible(true);

    //    chooser = new JFileChooser();

    //    chooser.setVisible(true);

    }



}

 

你可能感兴趣的:(GUI)