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 2 of 2

Thread: JFrame in event despatch thread

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Location
    Manchester
    Posts
    17
    My Mood
    Stressed
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default JFrame in event despatch thread

    I normally create a jframe with all the standard methods but I was reading about GUI on the oracle website and it showed an example of creating a jframe in a new instantce of runnable on something called an event despatch thread hear is the link Creating the Demo Application (Step 1) (The Java™ Tutorials > Creating a GUI With JFC/Swing > Performing Custom Painting) can you tell me the benefits of using this and what it does exactly, thanks.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,607
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: JFrame in event despatch thread

    Everything Swing related is done on the EDT, or Event Dispatching Thread. Painting, event handling, gui updating, etc. This keeps things organized, as making changes to the GUI from multiple Threads can result in pandemonium.

    So, if you're doing something on another Thread and you want to make a change to the gui, you should do it on the EDT. You do that by calling invokeLater() or invokeAndWait().

    And since technically the main Thread (the Thread that invokes the main method) is a separate Thread, it's a good practice to use invokeLater() or invokeAndWait() to make gui changes, including creating and showing a JFrame.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    DanielJamesCollier (April 25th, 2012)

Similar Threads

  1. event does not occur
    By sukanya in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 9th, 2012, 12:43 AM
  2. Event Issues
    By fractalorbit in forum AWT / Java Swing
    Replies: 3
    Last Post: September 2nd, 2011, 08:49 PM
  3. Event Handling
    By maress in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 24th, 2011, 03:29 AM
  4. After a rowInserted() event!
    By MarkusHendersonicus in forum JDBC & Databases
    Replies: 1
    Last Post: December 20th, 2010, 12:55 PM
  5. Event handling
    By subhvi in forum AWT / Java Swing
    Replies: 3
    Last Post: August 26th, 2009, 12:20 PM

Tags for this Thread