Solved

canvas repaint

Posted on 1999-01-21
1
664 Views
Last Modified: 2011-09-20
I have an applet with a class "Square" that extends canvas.
Below is an example of my code :

private Square square;
private TextArea textarea;

public void init () {
     textarea = new TextArea();
     square = new Square();
}

.....   //other codes
.....

public void repaintingCanvas() {
        textarea.append ("testing");       //line 1
        square.repaint();                  //line 2  
        textarea.append ("after testing"); //line 3
        }    


How come I will be able to see the execution of line 1 and line 3 first before seeing the execution of line 2. I tried to "sleep" the applet after line 2, hoping to see the effect of square.repaint()incase it takes time to repaint, but it will still sleep then I can see the words "after testing" in textarea (execution of line 3) and only later will I see the effect of repaint() of the particular canvas.

 Why is this so, is it because I am not optimizing my codes properly or because all directions of applet will be executed first and execution of canvas is done later.

fyi....applet implements runnable

0
Comment
Question by:caphey
[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
1 Comment
 
LVL 16

Accepted Solution

by:
heyhey_ earned 100 total points
ID: 1234475
painting is usually done in another Thread (probably the standard event Thread) so:

- when you call repaint() you just make request for repainting, which may be server some time later.
- when you call repaint from the code that is triggered from some  Event (for example actionPerformed() of a Button) you are working INSIDE the event Thread, so paining (and all other events propagation) will be BLOCKED until you quit the event handler method. sleep() won't help too.

it a standard practice to place all the 'heavy' code inside another Thread, so that you don't block the system event&paint Thread.

if you need more help, you'd better post a small example that reproduces yout problem.

best regards
  heyhey

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn different types of Android Layout and some basics of an Android App.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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 …
Suggested Courses

623 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