Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/barteo/midp/examples/simpledemo/GaugePanel.java


1   /*
2    *  MicroEmulator
3    *  Copyright (C) 2001 Bartek Teodorczyk <barteo@it.pl>
4    *
5    *  This library is free software; you can redistribute it and/or
6    *  modify it under the terms of the GNU Lesser General Public
7    *  License as published by the Free Software Foundation; either
8    *  version 2.1 of the License, or (at your option) any later version.
9    *
10   *  This library is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   *  Lesser General Public License for more details.
14   *
15   *  You should have received a copy of the GNU Lesser General Public
16   *  License along with this library; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19   
20  package com.barteo.midp.examples.simpledemo;
21  
22  import javax.microedition.lcdui.Command;
23  import javax.microedition.lcdui.CommandListener;
24  import javax.microedition.lcdui.Display;
25  import javax.microedition.lcdui.Displayable;
26  import javax.microedition.lcdui.Form;
27  import javax.microedition.lcdui.Gauge;
28  
29  
30  public class GaugePanel extends Form implements ScreenPanel, CommandListener
31  {  
32    private static final String NAME = "Gauge";
33    
34    private static final Command backCommand = new Command("Back", Command.BACK, 1);
35    
36    boolean cancel = false;
37  
38    private Gauge noninteractive = new Gauge("Noninteractive", false, 25, 0);
39    
40    private Runnable timerTask = new Runnable()
41    {
42      
43      public void run()
44      {
45        while (!cancel) {
46          if (isShown()) {
47            int value = noninteractive.getValue();
48        
49            if (noninteractive.getValue() >= 25) {
50              noninteractive.setValue(0);
51            } else {
52              noninteractive.setValue(++value);
53            }
54          }
55          try {
56            Thread.sleep(500);
57          } catch (InterruptedException ex) {
58            break;
59          }
60        }
61      }
62    };
63    
64    
65    public GaugePanel()
66    {
67      super(NAME);
68      
69      append(new Gauge("Interactive", true, 25, 0));
70      append(noninteractive);
71      
72      Thread thread = new Thread(timerTask, "GaugePanel");
73      thread.start();
74  
75      addCommand(backCommand);
76      setCommandListener(this);
77    }
78    
79  
80    public String getName()
81    {
82      return NAME;
83    }
84  
85  
86    public void commandAction(Command c, Displayable d)
87    {
88      if (d == this) {
89        if (c == backCommand) {
90          Display.getDisplay(SimpleDemo.getInstance()).setCurrent(SimpleDemo.getInstance().menuList);
91        }
92      }
93    }
94    
95  }