I am trying to further understand the program I am learning and I have an "Unresolved compilation problem"
Here is the program I am trying to run
Please help me to fix it and thanks for helping me to fix my last attempt.
import java.awt.FlowLayout; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JButton; import javax.swing.JFrame; public class Frames3 extends JFrame implements ActionListener { private static final long serialVersionUID = 1L; public static void main(String[] args) { new Frames3().setVisible(true); } private Frames3() { super("Tutorial = Rhoen MoreFrame"); setSize (600,600); setDefaultCloseOperation (EXIT_ON_CLOSE); setLayout (new FlowLayout()); JButton button = new JButton ("Click me"); JButton button2 = new JButton("Button 2"); button.addActionListener(this); button2.addActionListener(this); add (button); } public void actionPerformed(ActionEvent e) { String name = e.getActionCommand(); if (name.equals("Click me")) System.out.println("Click me"); } else if (name.equals("Button 2")) { System.out.println("Button 2 has been pressed"); } } }
Error message
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at Frames3.main(Frames3.java:12)
The error is in this line " else if (name.equals("Button 2"))"