Solved

Java Swing not working...

Posted on 2010-08-25
2
614 Views
Last Modified: 2013-12-14
I'm a beginner to Java and was trying to complete a Swing tutorial.  I entered the code and ran it, but did not get the pop up window as the tutorial suggested i would.

Not sure what's not included in my code or files.  I don't have any errors showing up in Eclipse.  I have one warning: The serializable class Simple does not declare a static final serialVersionUID field of type long - but i don't think that's the problem.  When I run the code I get the following in the Console area of the Eclipse IDE:


Usage: javaw [-options] class [args...]
           (to execute a class)
   or  javaw [-options] -jar jarfile [args...]
           (to execute a jar file)

where options include:
    -server        to select the "server" VM
    -hotspot        is a synonym for the "server" VM  [deprecated]
                  The default VM is server.
                 
    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A ; separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
    -D<name>=<value>
                  set a system property
    -verbose[:class|gc|jni]
                  enable verbose output
    -version      print product version and exit
    -version:<value>
                  require the specified version to run
    -showversion  print product version and continue
    -jre-restrict-search | -jre-no-restrict-search
                  include/exclude user private JREs in the version search
    -? -help      print this help message
    -X            print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
                  enable assertions
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
                  disable assertions
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
    -agentlib:<libname>[=<options>]
                  load native agent library <libname>, e.g. -agentlib:hprof
                    see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
                  load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
                  load Java programming language agent, see java.lang.instrument
    -splash:<imagepath>
                  show splash screen with specified image


I've attached my code below.  Any help would be appreciated!  Thanks!
package jSwing;



import javax.swing.JFrame;





public class Simple extends JFrame {



    public Simple() {



        setSize(300, 200);

        setTitle("Simple");

        setDefaultCloseOperation(EXIT_ON_CLOSE);

   }



    public static void main(String[] args) {



        Simple simple = new Simple();

        simple.setVisible(true);



    } 

}

Open in new window

0
Comment
Question by:slightlyoff
2 Comments
 
LVL 4

Accepted Solution

by:
javaftper earned 500 total points
ID: 33521141
I have added the serialVersionUID. Update your class as below and try again- it works on my eclipse setup now.

import javax.swing.JFrame;


public class Simple extends JFrame {

    // declare serialVersionUID
      private static final long serialVersionUID = 1L;

      public Simple() {

        setSize(300, 200);
        setTitle("Simple");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
   }

    public static void main(String[] args) {

        Simple simple = new Simple();
        simple.setVisible(true);

    }
}
0
 
LVL 1

Author Closing Comment

by:slightlyoff
ID: 33521188
Thanks :)  I swear I tried that, but after putting your code in, it worked.  I appreciate the help!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
eclipse compiler vs Installed JREs option 3 77
Problem to start Neon 20 89
java jdbc batch example 8 23
servlet example issue 6 33
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now