J2ME repaint
I'm having problems updating the display.
I have created a BusyCanvas which uses a timer and a task to display to the screen 'Busy.....' in an animated way.
Within a function in my MIDlet I call a fuction to download an image from the web. While downloading the 'Busy.....' must be displayed. The current display is set to BusyCanvas and the thread is running (tested it), but it wont call the paint method of BusyCanvas.
Here is the code sections...
//-
public class ImageViewer extends MIDlet {
//some code ....
//-
public void viewMap(String aFilename) throws Exception {
InambaCanvas canvas;
Display.getDisplay(this).setCurrent(fBusyCanvas);
fBusyCanvas.start();
fImage = InambaCanvas.getImage( aFilename );
canvas = new InambaCanvas();
canvas.setImage( fImage );
canvas.addCommand( new Command( "Back", Command.CANCEL, 1 ) );
canvas.setCommandListener(this);
fBusyCanvas.stop();
Display.getDisplay(this).setCurrent(canvas);
}
}
//-
public class BusyCanvas extends Canvas {
static String fBusyMessage = "Busy";
static String fLoadingMessage = "Loading";
boolean fPainting;
String fDotted;
Timer fTimer;
TimerTask fTask;
//--
public BusyCanvas() throws Exception {
super();
fPainting = false;
fTimer = new Timer();
fTask = new BusyTask();
fDotted = "";
}
//--
protected void paint(Graphics g) {
if (!fPainting) {
fPainting = true;
g.setColor( 0xFFFFFF );
g.fillRect( 0, 0, getWidth(), getHeight() );
g.setColor( 0 );
g.drawString( fBusyMessage + fDotted, getWidth()/2, getHeight()/2, Graphics.HCENTER | Graphics.TOP );
fPainting = false;
}
}
//--
public void start() throws Exception {
fTimer.scheduleAtFixedRate( fTask, 0, 500 );
}
//--
public void stop() throws Exception {
fTimer.cancel();
}
//--
class BusyTask extends TimerTask {
//--
public BusyTask() throws Exception {
super();
}
//--
public void run() {
if (fDotted.length() > 5) {
fDotted = "";
} else {
fDotted = fDotted.concat( "." );
}
repaint();
}
//--
}
//--
}

