I am learning Java on my own
I am not in school and my progress is slow but I think , sure
This forum has been extremely useful to me and thanks
Here is the code I am having a problem with. Please help me to fix it
Thanks
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 Menu1 extends JFrame implements ActionListener
{
// opens jframe
private static final long serialVersionUID = 1L;
public static void main (String[] args)
{
//opens main
new Menu1().setVisible(true);
}
private Menu1()
{
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 saveMenuItem = 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);
file.add (newMenuItem);
file.add(save);
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);
}
}
}
When I run it I get the following message
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
save cannot be resolved
at Menu1.<init>(Menu1.java:48)
at Menu1.main(Menu1.java:20)
What does this mean
I notice a X beside the line (file.add(save)
and save does not appear in the menu created