⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gaugedemo_1.java

📁 这是我收集的别人写的关于基本控件的例子
💻 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为用户可以调整",true,10 ,1 );
        g2=new GaugeThread("nonInteractive为用户不可以调整",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();

        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -