java left logo
java middle logo
java right logo
 

Home arrow Java ME Tips
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4091
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to create a List in MIDP E-mail
User Rating: / 8
PoorBest 

This example shows how to create a List in MIDP.


Image

/* License
 
 * Copyright 1994-2004 Sun Microsystems, Inc. All Rights Reserved.
 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *  
 *  * Redistribution of source code must retain the above copyright notice,
 *      this list of conditions and the following disclaimer.
 
 *  * Redistribution in binary form must reproduce the above copyright notice,
 *      this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 
 * Neither the name of Sun Microsystems, Inc. or the names of contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *  
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
 * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
 * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN")
 * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
 * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
 * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
 * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
 * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 *  
 * You acknowledge that this software is not designed, licensed or intended
 * for use in the design, construction, operation or maintenance of any
 * nuclear facility. 
 */

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class ListDemoMIDlet extends MIDlet {

    private Display              display;
    private int                  mode = List.IMPLICIT;

    private Command exitCommand = new Command"Exit",
                                   Command.SCREEN, );
    private Command selectCommand = new Command"Select",
                                       Command.OK, );
    private Command nextCommand = new Command"Next",
                                   Command.SCREEN, );
    public ListDemoMIDlet(){
    }

    protected void destroyAppboolean unconditional )
                   throws MIDletStateChangeException {
        exitMIDlet();
    }

    protected void pauseApp(){
    }

    protected void startApp() throws
    MIDletStateChangeException {
        ifdisplay == null ){ // first time called...
            initMIDlet();
        }
    }

    private void initMIDlet(){
        display = Display.getDisplaythis );
        display.setCurrentnew SampleListmode ) );
    }

    public void exitMIDlet(){
        notifyDestroyed();
    }

    public static final String[] items = {
        "First""Second""Third""Fourth"
    };


    class SampleList extends List implements
                           CommandListener {

        private int mode;

        SampleListint mode ){
            super"", mode, items, null );
            addCommandexitCommand );
            addCommandselectCommand );
            addCommandnextCommand );
            setCommandListenerthis );

            switchmode ){
                case IMPLICIT:
                    setTitle"Implicit" );
                    break;
                case EXCLUSIVE:
                    setTitle"Exclusive" );
                    break;
                case MULTIPLE:
                    setTitle"Multiple" );
                    break;
            }

            this.mode = mode;
        }

        public void commandActionCommand c,
                             Displayable d ){
            ifc == exitCommand ){
                exitMIDlet();
            else ifc == selectCommand ){
                showSelectionfalse );
            else ifc == SELECT_COMMAND ){
                showSelectiontrue );
            else ifc == nextCommand ){
                ifmode == List.IMPLICIT ){
                    mode = List.EXCLUSIVE;
                else ifmode == List.EXCLUSIVE ){
                    mode = List.MULTIPLE;
                else {
                    mode = List.IMPLICIT;
                }

                display.setCurrentnew SampleList(
                                             mode ) );
            }
        }

        private void showSelectionboolean implicit ){
            Alert alert = new Alert(
                       implicit ? "Implicit Selection"
                               "Explicit Selection" );
            StringBuffer buf = new StringBuffer();

            ifmode == MULTIPLE ){
                boolean[] selected = new booleansize() ];
                getSelectedFlagsselected );

                forint i = 0; i < selected.length; ++i ){
                    ifselected[i] ){
                        ifbuf.length() == ){
                            buf.append(
                             "You selected: " );
                        else {
                            buf.append", " );
                        }

                        buf.appendgetString) );
                    }
                }

                ifbuf.length() == ){
                    buf.append"No items are selected." );
                }
            else {
                buf.append"You selected " );
                buf.appendgetString(
                       getSelectedIndex() ) );
            }

            alert.setStringbuf.toString() );
            alert.setTimeoutAlert.FOREVER );

            display.setCurrentalert,display.getCurrent() );
        }
    }
}

 Related Tips


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.