Menus:
Menus are just like buttons - you will add them and a actionlistener. In actionPerformed, if the source is them, do something. Below is an example
//as globals
private JMenuBar menuBar=new JMenuBar();
private JMenu fileMenu=new JMenu("File");
private JMenuItem openMenuItem=new JMenuItem("Open");;
private JMenuItem saveMenuItem=new JMenuItem("Save");
//in init
menuBar.add(fileMenu);
fileMenu.add(openMenuItem);
fileMenu.add(saveMenuItem);
openMenuItem.addActionListener(this);
saveMenuItem.addActionListener(this);
setJMenuBar(menuBar);
|