Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Trying to create a window...

  1. #1
    Member
    Join Date
    Mar 2012
    Posts
    37
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Trying to create a window...

    Here's my code:

    import javax.swing.* ;

    class Window extends JFrame

    {
    public static void main ( String[] args){
    }
    JPanel pnl = new JPanel() ;
    public Window()
    {
    super( "Swing Window" ) ;
    setSize( 500, 200 ) ;
    setDefaultCloseOperation( EXIT_ON_CLOSE ) ;
    add( pnl ) ;
    setVisible( true ) ;
    }
    Window gui = new Window() ;
    }

    When I run it with Bluej I get a flickering window that doesn't seem right. Any thoughts? Thanks in advance.


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Trying to create a window...

    Java will start running what is in your main method. Well what is currently in your main method?

    public static void main ( String[] args){
      // not much here!
    }

    I think you'll want to put some relevant code in there so that Java will have some code to run. Experiment with this, try different things, and you'll see. Also please read the tutorials as this is all explained there quite well.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Trying to create a window...

    Please read the announcements thread for instructions on how to wrap your code to preserve formatting.

Similar Threads

  1. Replies: 2
    Last Post: August 27th, 2012, 09:19 PM
  2. Replies: 1
    Last Post: December 17th, 2011, 03:32 AM
  3. Replies: 2
    Last Post: October 31st, 2011, 09:19 AM
  4. Craating non active window ,and inputing to the non active window.
    By java-beginner in forum Java Theory & Questions
    Replies: 0
    Last Post: February 25th, 2011, 10:13 PM
  5. cmd.exe DOS Window
    By Curious in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: March 1st, 2010, 10:30 AM