Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The short answer could be: in method <code>slajd</code>, after call to <code>repaint();</code>, add</p> <pre><code>Thread.sleep(1000); </code></pre> <p>However, this is completely contrary to the event-based nature of Swing, and in this particular case doesn't even work because, for efficiency reasons, Swing does not execute <code>repaint()</code> calls immediately. It "collects" and executes them only once after all event processing has concluded. If you include an sleep period (or any other long-running operation) in an event handler (directly or indirectly), repainting will be delayed and the application be extremely unresponsive to the point, as in this case, of not really be working.</p> <p>What you need to do is in <code>createGUI</code> instantiate a Swing Timer (<code>javax.swing.Timer</code>; do not confuse it with <code>java.util.Timer</code>, or <code>Timer</code> classes in a few other packages) that fires every 1 second instead of calling <code>slajd()</code>. First firing should be immediate, or you could include code to display the first file. The associated listener, which would replace <code>slajd()</code> should keep track of the next file to display. You will most probably want to make this listener a full-fledged class with fields to support this tracking, a pointer to the <code>ImagePanel</code> where to display files, etc.</p> <p>For more information, read <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html" rel="nofollow">Java's Tutorial on How to Use Swing Timers</a></p>
 

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