Reputation:
I have a dialog box to be shown but it is giving compilation errors. The compilation errors are given in the last part.
import javax.swing.*;
class SwingDemo {
SwingDemo() {
JFrame jfrm = new JFrame("A Simple Swing Application");
jfrm.setSize(275, 100);
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel jlab = new JLabel(" Swing means powerful GUIs.");
jfrm.add(jlab);
jfrm.setVisible(true);
}
public static void main(String args[]) {
public void run() {
new SwingDemo();
}
}
}
The errors are:
Multiple markers at this line
- Syntax error on token "void", @ expected
- Syntax error, insert "enum Identifier" to complete EnumHeaderName
- Syntax error, insert "EnumBody" to complete BlockStatements
Upvotes: 3
Views: 223
Reputation: 36
Just replace your main function with this.
public static void main(String args[]) {
// Create the frame on the event dispatching thread.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new SwingDemo();
}
});
}
Upvotes: 6
Reputation:
First of all, do you use an IDE?
Your run() method is inside your main() method. You don't need a run method anyway. Just instantiate from main() new SwingDemo(); and remove the run() function like this:
public static void main(String[] args) {
new SwingDemo();
}
Upvotes: 0