File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Calling paint(g) has no affect during processor intensive activity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Calling paint(g) has no affect during processor intensive activity" Watch "Calling paint(g) has no affect during processor intensive activity" New topic
Author

Calling paint(g) has no affect during processor intensive activity

zhang lan
Greenhorn

Joined: Feb 23, 2010
Posts: 2
Hi,

I am writing a small game to improve my Java knowledge. When the game setups, a lot of calculations are made and a lot of data is stored to a flat file. This takes about 5 seconds.

Whilst this is happening, I want a message to appear on the screen saying "Please wait".

However, before this message can be displayed properly, the program starts on the calculations. Only when the calculations are finished does the message appear briefly.

Is there a method I can call or a piece of code I can use which checks that the message has been displayed before the processor intensive code is carried out?

Thanks for any help on this matter.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

Zhang,
Welcome to the Ranch.

Recommended reading http://java.sun.com/docs/books/tutorial/essential/concurrency/
What you need to do is put your computations and screen painting on different threads.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4664
    
    5

Also, never call paint(g). Complete a round of calculations and call repaint().
http://java.sun.com/docs/books/tutorial/uiswing/painting/index.html


luck, db
There are no new questions, but there may be new answers.
zhang lan
Greenhorn

Joined: Feb 23, 2010
Posts: 2
Hi, thanks for the help, I will try implementing them and let you know how it goes!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Calling paint(g) has no affect during processor intensive activity