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

asked Apr 9, 2012 at 9:23
2
  • 1
    please post the excat error message.. Commented Apr 9, 2012 at 9: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. Although they had a disturbing tendency to ignore the EDT rule, in general much better code. Commented Apr 9, 2012 at 10:05

3 Answers 3

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.

answered Apr 9, 2012 at 9:29
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, thats a realy simpel solution, but it works very fine ;)
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.

answered Apr 9, 2012 at 9:31

Comments

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.*;
answered Apr 9, 2012 at 9:34

2 Comments

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.
Ajj, I agree with you. I missed this screenshot.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.