Solved

how to force repaint()?

Posted on 1998-12-24
3
873 Views
Last Modified: 2008-03-17
Hi,

  My code has the following structure:

for(int i = 0; i < 10000; i++) {
  do some calculation;
  drawCanvas.repaint();
}

What I want is to do some calculation and plot the progress, and so on. But it seems that only after the loop is finished, the my "drawCanvas" is repainted(WM_PAINT message is blocked). May I know how to force painting? In MFC, we can use GetClientDC() to obtain a graphic device to draw on. Is there anything similar in Java? By the way, I need this to be done with JDK1.0.2 for maximum compatibility.
Thanks for your time.

wyldsj
0
Comment
Question by:wyldsj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
gadio earned 20 total points
ID: 1230111
wyldsj, the repaint method notifys the awt thread that it needs to start a paint cycle. Now there are two options:
1. Your loop is done by the awt thread (for example inside one of the event handlers etc.). In that case, you have to change the design because the awt thread shouldn't be doing cpu intensive tasks.
2. You are doing the loop on a different thread, and your thread is very cpu intensive. There is a chance that the awt thread get very little reasources (cpu time), and what you can do is use the  command:  Thread.currentThread().yield();  After you are issueing the repaint(). This will cause the current thread to give up the cpu and give the awt thread the chance to do its work.

Hope this helps.
G
0
 

Author Comment

by:wyldsj
ID: 1230112
gadio: you are right. My loop is within an event handler. It actually occurs after a button is clicked. But I cannot figure out a different structure... Is there any suggestions from you?

wyldsj
0
 

Author Comment

by:wyldsj
ID: 1230113
Hi! I just figured it out myself and it worked now! Thanks for your help, gadio!

wyldsj
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
login jsp example 24 105
How do I remove an object from a 3 63
jsp CRUD operations with and without prepared statement also hibernatge 1 50
junit initializtion error 2 22
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question