Fixing your indentation your code looks like this
package helloworld;
import javax.swing.*;
import java.awt.event.*;
public class FourthApp extends JFrame implements ActionListener {
JFrame interfaceFrame;
JButton startButton, stopButton;
public FourthApp() {
JFrame.setDefaultLookAndFeelDecorated(true);
interfaceFrame = new JFrame("GUI");
interfaceFrame.setSize(200,200);
interfaceFrame.setVisible(true);
interfaceFrame.setLayout(new java.awt.GridLayout(1,2));
startButton = new JButton("Start");
startButton.addActionListener(this);
interfaceFrame.add(startButton);
stopButton = new JButton("Stop");
stopButton.addActionListener(this);
interfaceFrame.add(stopButton);
interfaceFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
interfaceFrame.setVisible(true);
}
public void actionPerformed(ActionEvent a) {
if(a.getSource() == startButton){
System.out.println("Start Button was Pressed");
}
if(a.getSource() == stopButton) {
System.out.println("Stop Button was Pressed");
}
}
}
public static void main(String[] args) {
new FourthApp();
}
}
Do you notice the problem? Namely that extra closing brace after the actionPerformed method that ends that class definition, meaning that it expects the next line to declare a new class/interface/enum. As the error says.
masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494