Travel List : List « J2ME « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » J2ME » List 




Travel List
Travel List

import java.io.IOException;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;

public class TravelList extends MIDlet implements CommandListener {
  private List mList;

  private Command mExitCommand, mNextCommand;

  public TravelList() {
    String[] stringElements = "A""B""C" };
    Image[] imageElements = loadImage("/airplane.png"), loadImage("/car.png"),
        loadImage("/hotel.png") };
    mList = new List("Reservation type", List.IMPLICIT, stringElements, imageElements);
    mNextCommand = new Command("Next", Command.SCREEN, 0);
    mExitCommand = new Command("Exit", Command.EXIT, 0);
    mList.addCommand(mNextCommand);
    mList.addCommand(mExitCommand);
    mList.setCommandListener(this);
  }

  public void startApp() {
    Display.getDisplay(this).setCurrent(mList);
  }

  public void commandAction(Command c, Displayable s) {
    if (c == mNextCommand || c == List.SELECT_COMMAND) {
      int index = mList.getSelectedIndex();
      Alert alert = new Alert("Your selection""You chose " + mList.getString(index".", null,
          AlertType.INFO);
      Display.getDisplay(this).setCurrent(alert, mList);
    else if (c == mExitCommand)
      notifyDestroyed();
  }

  public void pauseApp() {
  }

  public void destroyApp(boolean unconditional) {
  }

  private Image loadImage(String name) {
    Image image = null;
    try {
      image = Image.createImage(name);
    catch (IOException ioe) {
      System.out.println(ioe);
    }

    return image;
  }
}


           
       














Related examples in the same category
1.List DemoList Demo
2.List ImplicitList Implicit
3.List CheckBoxList CheckBox
4.List RadioButtonList RadioButton
5.GUI Test in MIDletGUI Test in MIDlet
6.Payment MIDletPayment MIDlet
7.multiple Choice Listmultiple Choice List
8.Implicit ListImplicit List
9.List Item MIDletList Item MIDlet
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.