Learning notes (1)-implement mobile phone screen Switching

Source: Internet
Author: User

When writing a mobile phone program, you often need to switch between screens. I didn't know how to do it at first. I read an example in the past two days. It's very simple, but it can explain the problem. To sum up. If anything is wrong, please correct it!
Function: there are multiple buttons in the main program. Each button corresponds to a function, and each function must be displayed on a different screen (element.
Implementation:
1. The main program must define a Display object, such as private Display display, which indicates the current screen. There are some Displayable objects. For example, Form and TextField are all subclasses of Displayable. In the main program, you can add a Displayable instance to the current screen by using dipslay. serCurrent (Displayable Instance name. The following procedure:
Private Display display;
Private Form form = new Form ("one Form");
Public void startApp ()
{
Display. setCurrent (form );
}
The role is to add the form to the current screen.
2. to switch between screens, you just need to put the display stuff you want to display into the display object of the main program. If a display is defined in the main program, the display of the main program will be referenced in another screen (I'll call it a target screen.
Development Environment: Win2000 server + Eclipse + WTK2.1
Use the following code:
MainMIDlet. java: the main program, a standard MIDlet.
Import javax. microedition. midlet. MIDlet;
Import javax. microedition. lcdui .*;
Public class MainMIDlet extends MIDlet implements CommandListener {
Private Display display;
Private Form form = new Form ("Wellcome !! ");
Private Command okCommand = new Command ("OK", Command. OK, 1); // Select OK to switch to the next Screen
Private Form ns;
Private StringItem si = new StringItem ("First Screen ","~ _~ ");
Public MainMIDlet ()
{
Form. addCommand (okCommand );
Form. append (si );
}
Public void startApp (){
Display = Display. getDisplay (this );
Display. setCurrent (form );
Form. setCommandListener (this); // Add CommandListener to form
}
Public void pauseApp (){
}
Public void destroyApp (boolean B ){
}
Public void commandAction (Command c, Displayable s)
{
If (c = okCommand)
{
Ns = new NextScreen (display, form); // the most important part is here :)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.