caphey
asked on
canvas repaint
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.