| Author |
Threads and Painting
|
Jake Cirino
Greenhorn
Joined: Jul 27, 2012
Posts: 10
|
|
Hey guys, today for some practice, I whooped up a code that generates randomly colored circles (noise) on the screen.
This is the code I wrote:
However, while it's running through that code, because it's not a thread(I think?) it doesn't allow you to close the program by hitting the X in the corner, you have to close it from eclipse.
I (tried) to write a code using a thread, but no circles are painted on the screen then:
Can someone tell me why this doesn't work, and how to fix it?
(Also, just for future reference, because of it painting so many images on the screen, and them not being removed the amount of RAM being used by the program increases by 1Mb every couple of seconds. How would I remove these circles from the screen, would I have to use double buffering?)
|
 |
Greg Brannon
Bartender
Joined: Oct 24, 2010
Posts: 530
|
|
If you significantly reduce the number of times you pass through the while loop - to a few hundred or maybe a 1000, you'll see more interesting results, and the GUI will respond to user input as it should once the while loop has completed. There's a lot that can be learned by messing around with a little program like the first one.
Put the second program away and come back to it after studying multi-threading (or concurrency) and graphics in Swing a bit more.
|
Learning Java using Eclipse on OpenSUSE 11.2
Linux user#: 501795
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
|
Which you can read about in Concurrency in Swing.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Threads and Painting
|
|
|