?? gaugedemo_1.java
字號:
//gaugeDemo.java file
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
class GaugeThread extends Gauge implements Runnable{
private static boolean state=true;
private int maxValue=0;
private int minValue=0;
public GaugeThread(String label,boolean interactive,int maxValue,int initialValue){
super(label,interactive,maxValue,initialValue);
this.maxValue=maxValue;
this.minValue=minValue;
}
public void run(){
int add=1;
while(true){
while(state){
int value=getValue();
if(value==maxValue) add=-1;
if(value==minValue) add=1;
value=value+add;
this.setValue(value);
try{
Thread.sleep(500);
}catch(Exception e){}
}
}
}
static void pause(){
state=!state;
}
}
public class gaugeDemo_1 extends MIDlet implements CommandListener
{
private Command exitCommand;
private Form mainform;
private Command pauseCommand;
GaugeThread g1,g2;
Dialog dlg=null;
public gaugeDemo_1()
{
pauseCommand=new Command("PAUSE",Command.ITEM,1);
exitCommand =new Command("Exit",Command.EXIT,1);
mainform = new Form("gauge實例");
dlg=new Dialog("world", "hello", 1,this ,new DialogListener() , mainform );
mainform.addCommand(exitCommand);
mainform.addCommand(pauseCommand);
mainform.setCommandListener(this);
g1=new GaugeThread("Interactive為用戶可以調(diào)整",true,10 ,1 );
g2=new GaugeThread("nonInteractive為用戶不可以調(diào)整",false,10 ,3);
mainform.append(g1);
mainform.append(g2);
mainform.get(0).setLayout(Item.LAYOUT_EXPAND|Item.LAYOUT_NEWLINE_AFTER);
mainform.get(1).setLayout(Item.LAYOUT_EXPAND|Item.LAYOUT_NEWLINE_AFTER);
}
protected void startApp( ) throws MIDletStateChangeException
{
Display.getDisplay(this).setCurrent(dlg);
Display.getDisplay(this).setCurrent(mainform);
new Thread(g1).start();
new Thread(g2).start();
}
protected void pauseApp( )
{
}
protected void destroyApp( boolean p1 )
{
}
public void commandAction(Command c,Displayable d)
{
if (c ==exitCommand)
{
destroyApp(false);
notifyDestroyed();
}
else if(c==pauseCommand){
GaugeThread.pause();
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -