001: /*
002: *
003: * Copyright (c) 2007, Sun Microsystems, Inc.
004: *
005: * All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * * Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: * * Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: * * Neither the name of Sun Microsystems nor the names of its contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032: package stringitem;
033:
034: import javax.microedition.lcdui.*;
035: import javax.microedition.midlet.MIDlet;
036:
037: /**
038: * This is the main class for the UI MIDP demo. This demo of the components
039: * available in the UI is designed for simplicity. Each UI element is
040: * demonstrated within a class of its own derived from either BaseDemo
041: * or BaseListDemo.
042: *
043: * @version 2.0
044: */
045: public class StringItemDemo extends MIDlet implements CommandListener,
046: ItemCommandListener {
047: private static final Command CMD_GO = new Command("Go",
048: Command.ITEM, 1);
049: private static final Command CMD_PRESS = new Command("Press",
050: Command.ITEM, 1);
051: private static final Command CMD_EXIT = new Command("Exit",
052: Command.EXIT, 1);
053: private Display display;
054: private Form mainForm;
055:
056: /**
057: * Signals the MIDlet to start and enter the Active state.
058: */
059: protected void startApp() {
060: display = Display.getDisplay(this );
061:
062: mainForm = new Form("String Item Demo");
063: mainForm.append("This is a simple label");
064:
065: StringItem item = new StringItem(
066: "This is a StringItem label: ",
067: "This is the StringItems text");
068: mainForm.append(item);
069: item = new StringItem("Short label: ", "text");
070: mainForm.append(item);
071: item = new StringItem("Hyper-Link ", "hyperlink",
072: Item.HYPERLINK);
073: item.setDefaultCommand(CMD_GO);
074: item.setItemCommandListener(this );
075: mainForm.append(item);
076: item = new StringItem("Button ", "Button", Item.BUTTON);
077: item.setDefaultCommand(CMD_PRESS);
078: item.setItemCommandListener(this );
079: mainForm.append(item);
080: mainForm.addCommand(CMD_EXIT);
081: mainForm.setCommandListener(this );
082: display.setCurrent(mainForm);
083: }
084:
085: public void commandAction(Command c, Item item) {
086: if (c == CMD_GO) {
087: String text = "Go to the URL...";
088: Alert a = new Alert("URL", text, null, AlertType.INFO);
089: display.setCurrent(a);
090: } else if (c == CMD_PRESS) {
091: String text = "Do an action...";
092: Alert a = new Alert("Action", text, null, AlertType.INFO);
093: display.setCurrent(a);
094: }
095: }
096:
097: public void commandAction(Command c, Displayable d) {
098: destroyApp(false);
099: notifyDestroyed();
100: }
101:
102: /**
103: * Signals the MIDlet to terminate and enter the Destroyed state.
104: */
105: protected void destroyApp(boolean unconditional) {
106: }
107:
108: /**
109: * Signals the MIDlet to stop and enter the Paused state.
110: */
111: protected void pauseApp() {
112: }
113: }
|