First of all I am realy new to java. I have a very simple piece of script:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JavaApplicationSchool extends JFrame {
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "Hello World");
JOptionPane.showMessageDialog(null, "Goodbye");
System.exit(0);
}
}
When trying to run this code with netbeans 7.1. (JDK installed), my IDE returns errors on the Import parts at the top of the code.
These errors has to do with finding the awt packages. Can someone tell me where these packeges needs to be located and where I can find them?
Via this screenshot you can see how my directory structure looks like at the moment
Thank you in advance
3 Answers 3
Write at the top
package javaapplicationschool;
If you had your source in a directory path a/b/c it would be package a.b.c; The error seems to be misleading, as the package statement is optional - when you put the sources in the root directory of the sources (a bad practice though).
You can see in the Files tab of NetBeans the directory structure.
1 Comment
package javaapplicationschool;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JavaApplicationSchool extends JFrame {
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "Hello World");
JOptionPane.showMessageDialog(null, "Goodbye");
System.exit(0);
}
}
Read more about package.
Comments
I can run this code in Eclipse. This is not errors but warnings I got. Try delete unused imports.
import java.awt.*;
import java.awt.event.*;
extends, a redundantSystem.exit(0)and is not created on the EDT. Given 4 redundancies & the buggy start-up in just 10 lines of code, my advice is as follows. Wherever you found that code, put it back there. It is not going to teach you anything worth knowing. Instead see the Java Tutorials. Although they had a disturbing tendency to ignore the EDT rule, in general much better code.