Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>invokeLater runs the Runnable in the Event Dispatch Thread which also is used for updating the GUI.<br> Your sleep is blocking this Thread so the GUI also does not get <em>serviced</em>, no updates can be done till you return from the invokeLater code.<br> That's why you should not do any long (time consuming) computations in this Thread. They should be done in an different (new) Thread.</p> <p><a href="http://java.sun.com/docs/books/tutorial/uiswing/concurrency/dispatch.html" rel="nofollow noreferrer">The Event Dispatch Queue</a> states</p> <blockquote> <p>Tasks on the event dispatch thread must finish quickly; if they don't, unhandled events back up and the user interface becomes unresponsive. </p> </blockquote> <p>Your code could be changed to (not tested):</p> <pre><code>public Example(){ System.out.println("Example started"); setBounds(100,100,200,200); System.out.println("cmGUI instantiated"); CheckingMessagesGUI cmGUI = new CheckingMessagesGUI(); System.out.println("Set cmGUI visible"); cmGUI.setVisible(true); cmGUI.validate(); Thread thread = new Thread(new Runnable() { try { System.out.println("timer started"); Thread.sleep(5000); System.out.println("timer done"); } catch(InterruptedException e) { } System.exit(0); }); thread.start(); } </code></pre> <p>EDIT: let's go a bit "deeper" (and it's my view of the working of Swing/AWT).<br> I suppose the "please wait" (see comments) should be displayed in the CheckingMessagesGUI class, but isn't.<br> That's related to the way the GUI works. It does not directly change anything on the display if you call the corresponding (Swing) methods (draw, setText, setLocation, ...); it just queues an Event in the Event Queue. The Event Dispatch Thread is (should be) the only Thread that reads this queue and process the events. As long as it is being blocked - by the sleep in this case - no changes to the GUI will be displayed. The GUI is frozen.</p> <p>EDIT2:<br> <code>invokeLater</code> the Runnable is <em>appended</em> to the end of the queue to be latter executed by the EDT after all pending events have been processed, the next command after the invokeLater call will be executed.<br> <code>invokeAndWait</code> same as above but the actual Thread blocks until the Runnable was executed (after pending events) by the EDT, that is, the command following the invokeAndWait will only get started after the submitted Runnable was executed.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload