Right now I'm working on a GUI program which uses the JButton class (found in an online Swing tutorial), with this code:
import javax.swing.JButton;
public class HelloWorld extends java.applet.Applet {
public static void main(String[] args) {
@ConstructorProperties(value="Click")
public JButton(String Click); //identifier expected and ; expected error from here
drawString("test",50,25);
}
}
The compiler gives an "identifier expected" error and a "; expected error". Why is that and what should I do?
Applet
s do not have a main method drawString
is... You declare an object using the syntax of [type] [identifier]
, ie JButton aButton
. You initlaise that variable with the new
keyword. JButton aButton = new JButton("Click");
You seem to lack a level of common Java language knowledge as well as a lack of knowledge of the Swing API
Start by going back to basic, starting with The Java™ Tutorials , looking at the topics convered by the section titled Trails Covering the Basics
Once you have that under your belt, take a look at Creating a GUI With JFC/Swing
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.