0

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

Arthur
  • 921
  • 3
  • 13
  • 25
  • 1
    please post the excat error message.. – NiranjanBhat Apr 09 '12 at 09:26
  • *"a very simple piece of script:"* That simple piece of 'script' (usually referred to as 'code', in Java terms), has 2 redundant imports, an unnecessary `extends`, a redundant `System.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](http://docs.oracle.com/javase/tutorial/). Although they had a disturbing tendency to ignore the EDT rule, in general much better code. – Andrew Thompson Apr 09 '12 at 10:05

3 Answers3

2

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.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
2
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.

Anuj Balan
  • 7,629
  • 23
  • 58
  • 92
0

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.*;
Boris Y.
  • 4,387
  • 2
  • 32
  • 50
  • You created a file in eclipse, copy pasted and run the program. It will surely work. In the question he had posted, he is writing the program in a file which is in "javaapplicationschool" folder. So it was not working for him. Only point he missed is using the 'package', where as you had created in the default package, which doesn't need package declaration. – Anuj Balan Apr 09 '12 at 09:44
  • Ajj, I agree with you. I missed this screenshot. – Boris Y. Apr 09 '12 at 09:51