The moose likes Java Micro Edition and the fly likes MIDP Canvas problem!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "MIDP Canvas problem!!!" Watch "MIDP Canvas problem!!!" New topic
Author

MIDP Canvas problem!!!

Gang Lu
Greenhorn

Joined: Aug 15, 2003
Posts: 7
Hi, Thank you for taking your time in advance.
I am working on MIDP project current. Basically, 3 thread are running: main MIDlet, animaion, Httpconnection. Animation class is a Canvas, I use showNotify() and hideNotify to control the animation image (i.e. start or stop the animation). When i click a menu, the request will be sent out and in the meantime, the animation canvas will show up with animation running to hide the network delay. Upon response from the server comming a Alert needed to show on screen replacing the animation. But it doesn't work, the anim canvas even does not be shown (which mean showNotify() never been called). if I comment the Alert, the anim canvas can work well.
what the problem, please give me some help! Any tricky way to do that?THanks a lot.
Frank Manno
Ranch Hand

Joined: Apr 06, 2003
Posts: 48
Originally posted by Gang Lu:
Hi, Thank you for taking your time in advance.
I am working on MIDP project current. Basically, 3 thread are running: main MIDlet, animaion, Httpconnection. Animation class is a Canvas, I use showNotify() and hideNotify to control the animation image (i.e. start or stop the animation). When i click a menu, the request will be sent out and in the meantime, the animation canvas will show up with animation running to hide the network delay. Upon response from the server comming a Alert needed to show on screen replacing the animation. But it doesn't work, the anim canvas even does not be shown (which mean showNotify() never been called). if I comment the Alert, the anim canvas can work well.
what the problem, please give me some help! Any tricky way to do that?THanks a lot.

Can you paste the code that you use to call the canvas and the alert? It may help figure out the problem.
Also, what thread are you making the calls from?


-- Frank
Gang Lu
Greenhorn

Joined: Aug 15, 2003
Posts: 7
Thanks a lot. Here is the procedure:
1. in Login Screen,when user input the username & password and click Signin menu,HTTP connection will established and doAuthenticate();
private void doAuthenticate() throws IOException {
....
// call HTTP connection Thread
httpPoster.sendRequest(....);
// set the animScreen to run the animation
Display.getDisplay(mMIDlet).setCurrent(mMIDlet.animScreen);
try {
synchronized (mMIDlet) {
// block the MIDlet thread and wait for the authentication result from the server.
mMIDlet.mMIDletBlocked = true;
mMIDlet.wait();
}
} catch (Exception e) {
.....
}
}
2. the animation is controled by showNotify()->(start anim) and hideNotify()->(stop anim). When the reponse from server is catched, the MIDlet will be notified and a Alert will be called to notice the user the result. here is the method in MIDlet class called when the response catched:
public void authenticationDone() {
infoScreen = new InfoScreen(this, httpPoster);
Display.getDisplay(this).setCurrent(infoScreen);
}
3.in Animation Screen class, here are the showNotify():
protected synchronized void showNotify() {
System.out.println("Animation Screen Canvas is Showing!");
if ( image == null ) {
for (int i=0; i < numFrames; i++)
{
try
{
image = Image.createImage("/frame_" + (i+1) +".png");
imageArray[ i ] = image;
} catch (IOException ioe)
{
System.out.println("IO Error while getting the PNG image!");
}
}
imageHSize = imageArray[0].getWidth();
imageVSize = imageArray[0].getHeight();
mMessage = null;
}
running = true;
new Thread(this).start();
}
Any other codes you need to clarify my question?
Many Thanks.
Frank Manno
Ranch Hand

Joined: Apr 06, 2003
Posts: 48
Gang,
Unless I missed it in your code, why not use an actual Alert object to display the alert?
Once you create your Alert, you can display the Alert and then the Canvas like so:

See if that helps.
[ August 19, 2003: Message edited by: Frank Manno ]
Gang Lu
Greenhorn

Joined: Aug 15, 2003
Posts: 7
Thanks a lot.
I create a simple Alert and call Display.setCurrent(alert, animScreen) right after midlet thread catching the reponse. Unfortunately, it does not work. Any other idea I could try? I am so desperate. Do you have any example code?
Many thanks.
Gang Lu
Greenhorn

Joined: Aug 15, 2003
Posts: 7
I use println() in ShowNotify() in animScreen. I thought if i call Display.setCurrent(animScreen) this ShowNotify() will be called. But it does not when the setCurrent(alert, animScreen) followed by it. If I comment out the setCurrent(alert, animScreen), ShowNotify() is called and animation Screen is running.
Frank Manno
Ranch Hand

Joined: Apr 06, 2003
Posts: 48
Gang,
Would you mind posting some more of the code... I can't seem to pinpoint the problem... Also, be sure to enclose your code within "[ code ][ /code ]" blocks (be sure to remove the extra spacing between the words and the braces), so that it makes it easier to read it.
Gang Lu
Greenhorn

Joined: Aug 15, 2003
Posts: 7
Thanks. Here is my code:
1. LoginScreen is used for input username and password

here is doAuthenticate() codes

2. receiveHttpResonse() is uesed to process the response from server

3. The problem is that if these two lines are used after
Display.getDisplay(mMIDlet).setCurrent(mMIDlet.animScreen) :

the animation canvas cannot be shown. If i remove them, the animation can be seen and working well.
please see previous post for detail about animation canvas.
What's the problem? Is my explain clear? Thanks a lot indeed.

[ August 21, 2003: Message edited by: Gang Lu ]
[ August 21, 2003: Message edited by: Gang Lu ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MIDP Canvas problem!!!