Java Reference
In-Depth Information
}
g2.setGrayScale (0);
g2.drawArc (0, 0, getWidth()-1, getHeight()-1, 0, 360);
if (offscreen != null)
g.drawImage (offscreen, 0, 0, Graphics.TOP | Graphics.RIGHT);
}
Listing 3.3 gives the complete source code for the buffered stopwatch.
Listing 3.3 BufferedStopWatch.java —The Complete Source Code of the Buffered
Stopwatch
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
class BufferedStopWatchCanvas extends Canvas implements Runnable {
int degree = 360;
long startTime;
int seconds;
Display display;
Image offscreen;
BufferedStopWatchCanvas (Display display, int seconds) {
this.display = display;
this.seconds = seconds;
if (!isDoubleBuffered() && false)
offscreen = Image.createImage (getWidth(), getHeight());
startTime = System.currentTimeMillis();
}
public void paint (Graphics g) {
Graphics g2 = offscreen == null
? g
: offscreen.getGraphics();
g2.setGrayScale (255);
g2.fillRect (0, 0, getWidth(), getHeight());
if (degree > 0) {
g2.setColor (255, 0, 0);
g2.fillArc (0,0, getWidth(), getHeight(), 90, degree);
display.callSerially (this);
}
g2.setGrayScale (0);
g2.drawArc (0, 0, getWidth()-1, getHeight()-1, 0, 360);
if (offscreen != null)
g.drawImage (offscreen, 0, 0, Graphics.TOP |
Graphics.RIGHT);
}
public void run() {
int permille = (int) ((System.currentTimeMillis()
- startTime) / seconds);
degree = 360 - (permille * 360) / 1000;
 
 
Search WWH ::




Custom Search