I want to begin to learn about GUI in java. However, when i try to copy a simple JFrame code from a tutorial website to Textpad and when I try to compile it, there is an error:
"C:\Programming\Java\Practice GUI\GUIPractice.java:7: error: invalid method declaration; return type required public MyFrame() { ^ 1 error"
This also happens when I also copy simple GUI code from other websites, What seems to be the problem? I know that a method must either be void or a return type, but why does the method not specify if void or if return-type, a datatype? This seems to be the syntax of GUI code for other sites.
Here is the code:
// file: EmptyFrame.java
// Adapted from Core Java, vol.1, by Horstmann & Cornell
import javax.swing.*;
class MyFrame extends JFrame {
public MyFrame() {
setTitle("My Empty Frame");
setSize(300,200); // default size is 0,0
setLocation(10,200); // default is 0,0 (top left corner)
}
public static void main(String[] args) {
JFrame f = new MyFrame();
f.show();
}
}
I tried this with the Netbeans IDE and the same error shows up. what seems to be the problem?