Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You're on to something with threads. GUI programming mandates threads, in most cases -- luckily, Java's threading API isn't too terrible (Python's is modeled on it, so it's doing <em>something</em> right).</p> <p>Don't be intimidated by threading, though -- it's intermediate, I'd say, but is something that every programmer should understand.</p> <p>There's a lot of information out there that would predispose you against threads. GUI applications, however, are one area where they are phenomenally useful. Opponents of threading would lead you to believe that an event-programming model would help you in this case, when really, it will not. The solutions that most who say "threading sucks" propose are often worse than threading itself.</p> <p>You could try to kludge your solution into a single thread, but it would require your CPU-intensive code to yield to the GUI at a predictable interval. That solution sucks. <strong>EDIT:</strong> Since others are suggesting that approach, let me elaborate on why it sucks: Unbeknownst to you, something is always being updated in a GUI. When you move a window on top and then back off, the entire region under that window is invalidated and code must execute -- in <em>your</em> process -- to redraw that section. Even if you are updating the GUI very quickly, this provides a negative user experience as simple GUI operations block entirely. Buttons highlight when you mouse over, sometimes. A user right clicks. All of these things require CPU time to implement, and if your solitary thread is chewing away on your GA, they will not happen. GUI code being executed is not only <em>your</em> code.</p> <p>Here's what appears to be a <a href="http://www.javapractices.com/topic/TopicAction.do?Id=153" rel="nofollow noreferrer">very useful article on the topic</a>.</p> <p>Two lessons in the trail on the topic are:</p> <ol> <li><a href="http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html" rel="nofollow noreferrer">Concurrency</a></li> <li><a href="http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html" rel="nofollow noreferrer">Concurrency in Swing</a></li> </ol>
 

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