Hi,

I made a simple midlet:

Display display;
RedBox rbox = new RedBox();
GreenBox gbox = new GreenBox();
...
class RedBox extends Canvas {
public void paint (Graphics g) {
g.setColor(255,0,0);
g.fillRect(5,5,50,10);
}
}
class GreenBox extends Canvas {
public void paint (Graphics g) {
g.setColor(0,255,0);
g.fillRect(5,25,50,10);
}
}
public void startApp() {
display = Display.getDisplay(this);
display.setCurrent(rbox);
display.setCurrent(gbox);
}

My idea is to paint BOTH box in the same phone display at once, but actually only gbox shown. It looks like rbox has been cleared before gbox has been painted.

Then, I modified the midlet, I added a timer to switch the display every 1 second :

Timer tmr = new Timer();
XTask task = new XTask();
int i = 0;
class XTask extends TimerTask {
public void run() {
if (i == 0) {
i = 1;
display.setCurrent(rbox);
} else {
i = 0;
display.setCurrent(gbox);
}
}
}

public void startApp() {
tmr.schedule(task, 1000, 1000);
}

Then I can see BOTH box in the same phone display. Why this happened? I meant, Why in the first code, I can only see the "last object"? Why in the second code, there was no "clearing". If there SHOULD be a "clearing before painting", then we will see 'flicker'.

What is the actual rule of displaying something in phone display?

I tested another code to switch form and canvas rectangle, I saw "flicker" :
...
form displayed
then cleared (NOT THE FORM TITLE!)
rectangle displayed
then cleared
form displayed
...

Anyone can give better explanataion what actually happen after executing Display.setCurrent()?

PS: Yes, I can draw both box in the same canvas object, but I made it like this just to study about how to access phone display.

Thanks in advance,