i was coding GUI in Java. i'm just a beginner and i can't figure out on what program is mistaken please help me on this:
Compilation error is:
helloworld\FourthApp.java:38: class, interface, or enum expected
public static void main(String[] args) {
^
helloworld\FourthApp.java:40: class, interface, or enum expected
}
^
2 errors
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();
}
}