The last time I said that I would fix the code.
Well I clicked on the error and eclipse suggested a fix and I used it and further placed two sub menus under "save"
I really do not know why the change worked
Why should I do this (file.add(save1) when I have already called the file save (JMenuItem save = new JMenu("Save")
Can you please help me to understand the code or send me a PDF on the extending JFrame
Thanks
Here is the new code
import java.awt.BorderLayout; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; public class Menu3 extends JFrame implements ActionListener { private static final long serialVersionUID = 1L; public static void main (String[] args) { new Menu3().setVisible(true); } private Menu3() { super("Tutorial = Rhoen Menu #1"); setSize (600,600); setResizable (false); setDefaultCloseOperation (EXIT_ON_CLOSE); JButton button = new JButton ("Click me"); button.addActionListener(this); button.setActionCommand("Click"); JMenuBar bar = new JMenuBar(); JMenu file = new JMenu ("File"); JMenuItem newMenuItem = new JMenu("New"); JMenuItem save = new JMenu("Save"); JMenuItem close = new JMenuItem("Exit"); close.addActionListener(this) ; JMenuItem extra = new JMenu("Extra"); JMenuItem hello = new JMenuItem("Hello"); JMenuItem hello2 = new JMenuItem("Hello 2"); extra.add(hello); extra.add(hello2); JMenuItem save1 = new JMenu("Save"); JMenuItem now = new JMenuItem("Now"); JMenuItem later = new JMenuItem("Later"); save1.add(now); save1.add(later); file.add (newMenuItem); file.add(save1); file.add(extra); file.addSeparator(); file.add(close); bar.add(file); add(button, BorderLayout.WEST); setJMenuBar (bar); } public void actionPerformed(ActionEvent e) { String name = e.getActionCommand(); if (name.equals("Click")) { System.out.println("Click me"); } else if (name.equals("Exit")) { System.out.println("Closed"); System.exit(0); } } }