Well, those examples were quite usefull -
however, I would like to create a "more dynamic" please wait screen.
One that also show a percentage rate of how much is finished loading.
( the percentage rate doesn't need to be exact, I decided just to update the
progress bar after creating a few things, with a new percentage rate that I guess.
From your tipps, this is my Code so far - it works to write "Loading"
and to print the progress bar - but it doesn't get updated, at least I can't see it.
This is the code of my ProgressBar
public class MyProgressBar extends GameCanvas implements Runnable {
static int WIDTH;
static int HEIGHT;
private int progress = 0;
public boolean LOADING = true;
private Graphics g;
private int barHeight = 0;
private int barLength = 0;
private int fortschrittLaenge = 0;
private Thread myThread;
public MyProgressBar () {
super(false);
g = getGraphics();
setFullScreenMode(true);
this.HEIGHT = getHeight();
this.WIDTH = getWidth();
this.barHeight = this.HEIGHT / 10;
this.barLength = (int)(this.WIDTH / 1.32);
myThread = new Thread(this);
myThread.start();
}
public void paint(Graphics g) {
g.setColor(BLACK);
g.drawRect(0, 0, WIDTH, HEIGHT);
g.setFont(LARGEFONT);
if(progress!=0) {
progressLength = barLength / progress;
}
else {
progressLength = 0;
}
g.setColor(GREY);
g.fillRect((WIDTH-barLength)/2, (HEIGHT-barHeight)/2, barLength, barHeight);
g.setColor(RED);
g.fillRect((WIDTH-barLength)/2, (HEIGHT-barHeight)/2, progressLength, barHeight);
g.drawString(" loading... ", 0, 0, 0);
}
public void setProgress(int progress) {
this.progress = progress;
}
public void run() {
while (LOADING) {
paint(g);
}
}
}
And here is my code for my GameCanvas Class
public MyGameCanvas(MyMidlet midlet, Highscore highscore, MyProgressbar progressBar) {
super(false);
g = getGraphics();
this.progressBar= progressBar;
progressBar.setProgress(1);
setFullScreenMode(true);
HEIGHT = getHeight();
WIDTH = getWidth();
this.midlet = midlet;
this.highscore = highscore;
myThread = new Thread(this);
myThread .start();
progressBar.setProgress(2);
}
run() {
someTimeTakingRoutines();
midlet.showMyCanvas();
...
..
.
}
public void someTimeTakingRoutines() { // init GameCanvas
createStuff();
progressBar.setProgress(10);
createMoreStuff();
progressBar.setProgress(30);
createMoreStuff();
progressBar.setProgress(50);
createMoreStuff();
progressBar.setProgress(70);
createMoreStuff();
progressBar.setProgress(100);
}
In my midlet, I have:
public void loadMyGame() {
myProgressBar = new ProgressBar();
display.setCurrent(progressBar);
myGameCanvasd = new MyGameCanvasd(this, highscore, myProgressBar);
}
And, after I loaded all game stuff in my GameCanvas Class I call this method in my midlet from my GameCanvasClass from its run method (see above)
public void showMyGameCanvas() {
display.setCurrent(myGameCanvas);
}
It does show the progressBar, but it doesn't get updated -
at least I can't see the changes.
Why?