java 菜单

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

public class MyMenu extends JFrame  implements ActionListener
{
    JMenuBar mb = new JMenuBar();
	JMenu    file = new JMenu("file");
	JMenu    edit = new JMenu("edit");
	JMenuItem    open = new JMenuItem("open");
	JMenuItem    close = new JMenuItem("close");
	JMenuItem    exit = new JMenuItem("Exit");
	JMenuItem    copy = new JMenuItem("copyword");
	JMenuItem    paste = new JMenuItem("Paste");

	public MyMenu(){
	
	    super("My Own MenuBar by swing JMenuBar");
        setJMenuBar(mb);
		mb.add(file);
		mb.add(edit);
		file.add(open);
		file.add(close);
                exit.addActionListener(this);
		file.add(exit);
		edit.add(copy);
		edit.add(paste);

		setSize(300,400);
		setVisible(true);
	}

	public static void main(String args[]){
	  
	    MyMenu M=new MyMenu();
	}

        public void actionPerformed(ActionEvent e){
	 
	    if(e.getSource()==exit)
			System.exit(0);
	   
	}
}

你可能感兴趣的:(java,swing)