Making use of Canvas MIDlet welcome interface
Usually, we release the software applications when the commencement of the proceedings will show a welcome interface may also be some information on the software, this article will be on how to produce their own interfaces such a welcome.
I have previously used the Environmental Alert done interface can be used display.setCurrent (alert, the next) method. This shows that the time when the alert end users or keys so will show that the next interface. This is essentially to meet our needs, but the effect of this is not ideal, I do not test cell phones on many occasions good. Here, I introduce a welcome interface using Canvas production method, in which will involve some of the contents of Timer and TimerTask, you can refer to my J2SE in the related use of this article to see how two simple and important class.
Our aim is to display a welcome to the user interface when users press any button or set the display to the time when it shows the principal interface. We like to create a succession WelcomeCanvas Canvas class in the paint (Graphics g) by providing a way to map the inside we welcome the interface picture. For example:
Protected void paint (Graphics arg0)
(
Int width = this.getWidth ();
Int height = this.getHeight ();
Image displayImage = null;
Try
(
DisplayImage = Image.createImage ( "/ Duke.png");
) Catch (IOException e)
(
E.printStackTrace ();
)
Arg0.drawImage (displayImage, width / 2, height / 2, Graphics.HCENTER
| Graphics.BOTTOM);
)
In WelcomeCanvas, we hope that when it was revealed that began when the time. This way we can cover showNotify (), as follows:
Protected void showNotify ()
(
Timer.schedule (new TimerTask ()
(
Public void run ()
(
Dismiss ();
)
), DisplayTime);
)
This canvas shows that the time when the system has already begun time, displayTime show will be the main interface. Perhaps users can not wait for such a long time, then when he keys, they also should show the main interface, we cover methods keyPressed () and pointerPressed () as follows:
Protected void keyPressed (int keyCode)
(
Dismiss ();
)
Protected void pointerPressed (int y, int x)
(
Dismiss ();
)
Private void dismiss ()
(
Timer.cancel ();
Display.setCurrent (nextUI);
)
This basic structure of our WelcomeCanvas up, we write a MIDlet to look at the test results, and the MIDlet WelcomeCanvas code reads as follows:
Note: This program is run in the eclipse of the environment, so you should be copied to the res Duke.png document directory Otherwise, it will throw an error. I was in this picture wtk install directory casually looking for.
Import javax.microedition.lcdui.Command;
Import javax.microedition.lcdui.CommandListener;
Import javax.microedition.lcdui.Display;
Import javax.microedition.lcdui.Displayable;
Import javax.microedition.lcdui.Form;
Import javax.microedition.midlet.MIDlet;
Import javax.microedition.midlet.MIDletStateChangeException;
/ *
* Created on 2004-7-28
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
* /
/ **
* @ Author E2412C
*
* TODO To change the template for this generated type comment go to Window –
* Preferences - Java - Code Style - Code Templates
* /
Public class MyMIDlet extends MIDlet
(
Private Display display;
Private Form mainForm = new Form ( "main form");
Protected void startApp () throws MIDletStateChangeException
(
Display = Display.getDisplay (this);
MainForm.append ( "this is the main form");
WelcomeCanvas welcome = new WelcomeCanvas (display, mainForm);
Welcome.setDisplayTime (6000);
Display.setCurrent (welcome);
)
Protected void pauseApp ()
(
)
Protected void destroyApp (boolean arg0) throws MIDletStateChangeException
(
)
)
Import java.io.IOException;
Import java.util.Timer;
Import java.util.TimerTask;
Import javax.microedition.lcdui.Canvas;
Import javax.microedition.lcdui.Display;
Import javax.microedition.lcdui.Displayable;
Import javax.microedition.lcdui.Graphics;
Import javax.microedition.lcdui.Image;
/ **
* @ Author E2412C
*
* TODO To change the template for this generated type comment go to Window –
* Preferences - Java - Code Style - Code Templates
* /
Public class WelcomeCanvas extends Canvas
(
Private Display display;
Private Displayable nextUI;
Private Timer timer = new Timer ();
Private long displayTime = 3000;
Public WelcomeCanvas (Display dis, Displayable disp) (
This.display = dis;
This.nextUI = disp;
)
Protected void paint (Graphics arg0)
(
Int width = this.getWidth ();
Int height = this.getHeight ();
Image displayImage = null;
Try
(
DisplayImage = Image.createImage ( "/ Duke.png");
) Catch (IOException e)
(
E.printStackTrace ();
)
Arg0.drawImage (displayImage, width / 2, height / 2, Graphics.HCENTER
| Graphics.BOTTOM);
)
Public void setDisplayTime (long dispTime)
(
This.displayTime = dispTime;
)
Protected void keyPressed (int keyCode)
(
Dismiss ();
)
Protected void pointerPressed (int y, int x)
(
Dismiss ();
)
Private void dismiss ()
(
Timer.cancel ();
Display.setCurrent (nextUI);
)
Protected void showNotify ()
(
Timer.schedule (new TimerTask ()
(
Public void run ()
(
Dismiss ();
)
), DisplayTime);
)
)








0 Comments to “Making use of Canvas MIDlet welcome interface”
No Comments. Send your comment.
Leave a Reply
You must be logged in to post a comment.