Repaint and Delay Problem
From: Doug van Vianen (courses_at_shaw.ca)
Date: 11/27/03
- Previous message: Tony Dahlman: "Re: thread"
- Next in thread: Chris Smith: "Re: Repaint and Delay Problem"
- Reply: Chris Smith: "Re: Repaint and Delay Problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 27 Nov 2003 02:14:40 GMT
I wrote the following short test applet to try to solve a problem but
have not had any luck. Hopefully someone can help me with a solution.
I simply wish to display a red letter 'A', wait a few seconds, and
then display a blue letter 'B'. I use the string 'cheatop' to let the
paint routine know which is to be displayed.
What happens is that when the applet loads, a three second delay occurs
okay and the blue letter 'B' is displayed. Nothing appears when the
red letter 'A' should appear before the delay.
What appears to be happening is that all of the painting is done after
the delay so that the red 'A' is overwritten by the blue 'B'. Is there any
way to force the first repaint to occur?
import java.applet.*;
import java.awt.*;
public class test extends java.applet.Applet {
String cheatop;
public void init() {
cheatop="A";
repaint();
try {
Thread.sleep(3000);
}
catch (InterruptedException e) {
}
cheatop = "B";
repaint();
}
public void update (Graphics g) {
paint(g);
}
public void paint(Graphics g) {
if (cheatop == "A") {
g.setColor(Color.red);
g.drawString("A", 20, 20);
}
if (cheatop == "B") {
g.setColor(Color.blue);
g.drawString("B", 20, 20);
}
}
}
Thank you.
- Previous message: Tony Dahlman: "Re: thread"
- Next in thread: Chris Smith: "Re: Repaint and Delay Problem"
- Reply: Chris Smith: "Re: Repaint and Delay Problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|