import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
class ItemClick implements ActionListener{
public void actionPerformed(ActionEvent e) {
Object obj = e.getSource();
JMenuItem itm = (JMenuItem)obj;
System.out.println(itm.getLabel());
}
}
public class JMenuDemo extends JFrame{
JMenuBar jmb;
JMenu jfile,jedit;
JMenuItem open,close,save,exit;
JMenuItem undo,cut,copy,paste;
public JMenuDemo(String str){
super(str);
jmb = new JMenuBar();
jfile = new JMenu("File");
jedit = new JMenu("Edit");
open = new JMenuItem("open");
open.addActionListener(new ItemClick());
close = new JMenuItem("close");
save = new JMenuItem("save");
exit = new JMenuItem("Exit");
undo = new JMenuItem("undo");
cut = new JMenuItem("cut");
copy = new JMenuItem("copy");
paste = new JMenuItem("paste");
this.setJMenuBar(jmb);
jfile.add(open);
jfile.add(close);
jfile.add(save);
jfile.addSeparator();
jfile.add(exit);
jedit.add(undo);
jedit.addSeparator();
jedit.add(cut);
jedit.add(copy);
jedit.add(paste);
jmb.add(jfile,0);
jmb.add(jedit,1);
this.setLocation(500,200);
this.setSize(350, 250);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true); }
public static void main(String[] args) {
new JMenuDemo("1902-17");
}
}