Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to force repaint()?

Posted on 1998-12-24
3
Medium Priority
?
875 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 80 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

670 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