Java swing error dialog
I have a dialog to display but it gives compilation errors. Compilation errors are listed in the last section.
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();
}
}
}
Errors:
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
+3
user4323984
source
to share
2 answers
First of all, are you using an IDE?
Your run () method is inside your main () method. You don't need a startup method anyway. Just create an instance from main () of the new SwingDemo (); and remove the run () function like this:
public static void main(String[] args) {
new SwingDemo();
}
0
user4232819
source
to share