Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java Swing program prob

Options
  • 27-05-2002 9:47pm
    #1
    Closed Accounts Posts: 288 ✭✭


    import javax.swing.*;

    public class HelloWorldSwing {

    public static void main(String[] args) {

    JFrame frame = new JFrame("HelloWorldSwing");
    final JLabel label = new JLabel("Hello World");
    frame.getContentPane().add(label);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);

    }
    }


    C:\java\HelloWorldSwing.java:2: Package javax.swing not found in import.
    import javax.swing.*;
    ^
    1 error



    It's supose to display "Hello world" in a window but I don't seem to have the classes needed for Swing. I have JDK1.1.8 and I downloaded JDK 1.2.2 today to see if that world work but I got the same error. I dirrected my complier ( JCreator LE - www.jcreator.com ) to both JDK 1.1.8 and JDK 1.2.2 directories.

    Can anyone tell me what I have to download or what I have to do to fix this error.

    Cheer's, BoB.


Comments

  • Registered Users Posts: 2,281 ✭✭✭DeadBankClerk


    Google Says:
    http://forum.java.sun.com/thread.jsp?thread=109755&forum=54&message=291267
    Guys,
    In the paths you have to include the ";" at the end of the
    classpath. Also notice the ".;" in the beginning of the line.


    set classpath=%classpath%;.;c:\jdk1.3\bin;


  • Closed Accounts Posts: 288 ✭✭TARE


    C:\jdk1.2.2\jre\lib\rt.jar;C:\jdk1.2.2\jre\lib\i18n.jar;C:\jdk1.2.2\lib\dt.jar;C:\jdk1.2.2\lib\tools.jar;C:\jdk1.2.2\jre\lib\ext\iiimp.jar;C:\jdk1.2.2\bin

    All of the class paths above where added automaticly when i dirrected JCreator to the JDK 1.2.2 director. I added the C:\jdk1.2.2\bin but I still getting the same error :(

    Maybe it's because there using JDK 1.3 ? I've already downloaded JDK 1.2.2 today which is 20 megs, I taught 1.2.2 was the latest version. Can anyone else tell me something I can do before I download another 20 megs ?


  • Registered Users Posts: 1,994 ✭✭✭lynchie


    Have you tried compiling the code from the command line first?

    Also, to ensure that you are using the correct version of the jre, open the rt.jar file in winzip and check that there is a folder in it called javax/swing with a load of java classes in it


  • Registered Users Posts: 15,443 ✭✭✭✭bonkey



    It's supose to display "Hello world" in a window but I don't seem to have the classes needed for Swing. I have JDK1.1.8 and I downloaded JDK 1.2.2 today to see if that world work but I got the same error. I dirrected my complier ( JCreator LE - www.jcreator.com ) to both JDK 1.1.8 and JDK 1.2.2 directories.
    [/B]

    In JCreator (which I use), you should have "auto-completion". Thus, when you do "import javax.", it should present you with a list of matches - one of which is swing on my machine.

    If you dont get this, then you definitely have a problem with your classes. Check the project settings to see what JDK Profile you have enabled. Then check the JDK Profile to see that it is set up correctly - it should have a number of classes (jars mostly) listed for you.

    I'm guessing your problem is with JCreator config, and not with java itself - you shouldnt need a newer version than 1.2.2 for what youre doing. Consider compiling from the command line to test this, or see about fixing your jcreator install.

    Oh - and get the full JCreator, as opposed to JC Lite. License it if you can afford to do so, because you then get access to the pre-release of 2.5 which is far far better.

    jc


  • Closed Accounts Posts: 288 ✭✭TARE


    Compiling from the command line is compiling from DOS ?
    I did this and got a new error.


    C:\WINDOWS>cd\

    C:\>path = c:\jdk1.2.2\bin

    C:\>cd java

    C:\java>javac HelloWorldSwing.java
    HelloWorldSwing.java:10: No variable EXIT_ON_CLOSE defined in class javax.swing.
    JFrame.
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ^
    1 error

    C:\java>

    In JCreator (which I use), you should have "auto-completion". Thus, when you do "import javax.", it should present you with a list of matches - one of which is swing on my machine.

    I'm not sure what you mean by "auto-completion" ?

    Cheers for the help so far, I'll look in to getting Jcreator Pro.


  • Advertisement
  • Registered Users Posts: 1,994 ✭✭✭lynchie


    Ok, Well this means that it is picking up the javax.swing.* classes in DOS. So it is obviously not picking up the correct classes within your IDE (JCreator).

    The reason why you are getting the compile error from dos is because that field was only added to jdk1.3

    Docs from jdk1.3
    EXIT_ON_CLOSE

    public static final int EXIT_ON_CLOSE

    The exit application default window close operation. If a window has this set as the close operation and is closed in an applet, a SecurityException may be thrown. It is recommended you only use this in an application.

    Since:
    1.3

    I cannot remember off hand what the old way of doing that was, but I think you should be able to comment out that line and get it compiling fine.


  • Closed Accounts Posts: 1,322 ✭✭✭phobos


    Is it just me or is 9/10 java oriented problems associated with CLASSPATHs on this board?

    The problem needs fixing so I will do a tutorial on it later on tonight. See back tomorrow for the full thing, or else late tonight. The tutorial will be jdk/ide independant so you can implement it anyway you want, and it will still work.

    Nobody needs to feel inferior just because they are getting CLASSPATH related errors. Because IMO it's something that people seem to overlook in the beginning when learning Java. A lot of command line gurus take it for granted, and then whinge when the compiler throws a java.lang.ClassNotFoundException :)

    I will post the link later, c ya ;)

    ;-phobos-)


  • Closed Accounts Posts: 1,322 ✭✭✭phobos


    Anyway,

    Here is my CLASSPATH tutorial

    HTH ;)

    ;-phobos-)


Advertisement