Article View: borland.public.jbuilder.java.language
Article #16035Why this doesn't work
From: Alexis Rios
Date: Thu, 08 Apr 1999 00:00
Date: Thu, 08 Apr 1999 00:00
62 lines
1762 bytes
1762 bytes
I'm trying to use some text at the applet using double buffering. The thing
is that the applet is always displaying this message:
My counter is: 1
and although is incrementing the variable counter, it always display 1
Thanks for any help
import java.awt.*;
import java.applet.*;
public class Applet1 extends Applet implements Runnable {
Thread runner;
Graphics offGr;
Image offImg;
int counter = 0;
public void run() {
while (true) {
try {
Thread.sleep(100);
} catch (InterruptedException e){
}
repaint();
}
}
public void init() {
offImg = createImage ( this.getSize().width,
this.getSize().height );
offGr = offImg.getGraphics();
}
public void start() {
if(runner == null) {
runner = new Thread(this);
runner.start();
}
}
public void stop() {
if (runner != null) {
runner.stop ( );
runner = null;
}
}
public void paint(Graphics g) {
counter++;
offGr.drawString("My counter is " + counter, 15,25);
g.drawImage ( offImg, 0, 0, this );
}
public void update(Graphics g) {
paint(offGr);
}
}
Technical Details
Message-ID:
<7eiopg$24c17@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,b4ed2ae2a3803097,start X-Google-Attributes: gidf74b3,public From: "Alexis Rios" <alexr@coqui.net> Subject: Why this doesn't work Date: 1999/04/08 Message-ID: <7eiopg$24c17@forums.borland.com> X-Deja-AN: 464103473 X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 Organization: Home PC X-MSMail-Priority: Normal Reply-To: "Alexis Rios" <alexr@coqui.net> Newsgroups: borland.public.jbuilder.java.language