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 gauge;
033:
034: import javax.microedition.lcdui.*;
035: import javax.microedition.midlet.MIDlet;
036:
037: /**
038: * This MIDlet demonstrates the different types of gauges supported by MIDP-2.0:
039: * Interactive -
040: * Non Interactive -
041: * Interactive -
042: * Indefinite Incremental
043: *
044: * @version 2.0
045: */
046: public class GaugeDemo extends MIDlet implements CommandListener {
047: private static final Command CMD_EXIT = new Command("Exit",
048: Command.EXIT, 1);
049: private Display display;
050: private NonInteractiveGaugeRunnable nonInteractive;
051: private IncrementalIndefiniteGaugeRunnable indefinite;
052: private Form mainForm;
053:
054: public GaugeDemo() {
055: display = Display.getDisplay(this );
056:
057: mainForm = new Form("Gauge Demo");
058: //
059: mainForm.append(new Gauge("Interactive", true, 10, 0));
060: //
061: nonInteractive = new NonInteractiveGaugeRunnable(
062: "Non Interactive", 10, 0);
063: new Thread(nonInteractive).start();
064: mainForm.append(nonInteractive);
065: //
066: mainForm.append(new Gauge("Indefinite - Running", false,
067: Gauge.INDEFINITE, Gauge.CONTINUOUS_RUNNING));
068:
069: indefinite = new IncrementalIndefiniteGaugeRunnable(
070: "Indefinite - Incremental");
071: new Thread(indefinite).start();
072: mainForm.append(indefinite);
073: mainForm.addCommand(CMD_EXIT);
074: mainForm.setCommandListener(this );
075: }
076:
077: /**
078: * Signals the MIDlet to start and enter the Active state.
079: */
080: protected void startApp() {
081: display.setCurrent(mainForm);
082: }
083:
084: /**
085: * Signals the MIDlet to terminate and enter the Destroyed state.
086: */
087: protected void destroyApp(boolean unconditional) {
088: nonInteractive.setDone();
089:
090: indefinite.setDone();
091: }
092:
093: /**
094: * Signals the MIDlet to stop and enter the Paused state.
095: */
096: protected void pauseApp() {
097: }
098:
099: public void commandAction(Command c, Displayable d) {
100: destroyApp(false);
101: notifyDestroyed();
102: }
103: }
|