Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, if you don't create a copy of the <code>Graphics</code> context, you shouldn't be disposing of it. This could actually prevent other parts of your application form been painted ;)</p> <p>Second of all. I would avoid extending from a top level container, like <code>JFrame</code>, apart from allowing you to draw under the frame/border decoration of the window, they aren't double buffered.</p> <p>Instead, I'd use something like a <code>JPanel</code> instead and override its <code>paintComponent</code> method. This will provide you with automatic double buffering.</p> <p>Because Swing is a single threaded framework, it is expected that all updates to the UI be executed within the context of the Event Diapatching Thread. </p> <p>This makes live a little difficult when it comes to try to do things like waiting and synchronizing paint updates.</p> <p>Luckly, Swing provides a <code>javax.swing.Timer</code> which allows you schedule an event for some time in the future. This can also be setup to repeat and regular intervals.</p> <pre><code>Timer timer = new Timer(40, new ActionListener() { public void actionPerformed(ActionEvent e) { // perform your required actions here } }); </code></pre> <p>Now, beware, the <code>actionPerformed</code> method is being executed with the context of the EDT, this means, that any long running/time consuming processing you do here may cause you UI to stop painting</p> <p>Take a look at </p> <ul> <li><a href="http://docs.oracle.com/javase/tutorial/uiswing/painting/" rel="nofollow">Performing Custom Painting</a></li> <li><a href="http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html" rel="nofollow">Intial Threads</a></li> <li><a href="http://docs.oracle.com/javase/tutorial/uiswing/concurrency/" rel="nofollow">Concurrency in Swing</a></li> </ul> <p>For more details...</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. 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.
 

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