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

📄 formtest2.java

📁 《精彩的手机UI例程.zip》是很好的手机编辑软件
💻 JAVA
字号:

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class FormTest2 extends MIDlet implements CommandListener, ItemStateListener{
    private Form    mainscreen;
    private Command okCommand = new Command("OK", Command.OK, 1);
    private Command exitCommand = new Command("Exit", Command.EXIT, 1);
    private Display display;
	
    public FormTest2() {
        mainscreen= new Form("Form demo");
        mainscreen.addCommand(okCommand);
        mainscreen.addCommand(exitCommand);
        mainscreen.setCommandListener(this);
        mainscreen.setItemStateListener(this);
		
        //create exclusive choice
        String[] editable_choices={"interactive", "noninteractive"};
        mainscreen.append(new ChoiceGroup("Gauge option",Choice.EXCLUSIVE,
				          editable_choices,null));

        //create a textfield
        mainscreen.append(new TextField("Reset Gauge value", "10", 20, TextField.NUMERIC));
        //create a Gauge
        mainscreen.append(new Gauge("Gauge Test",true,100,10));
			
        //retrieve display object 
        display=Display.getDisplay(this);
    }
	
    public void startApp() throws MIDletStateChangeException {
        display.setCurrent(mainscreen);
    }

    /**
     * Pause the MIDlet
     */
    public void pauseApp() {
    }

    /**
     * Called by the framework before the application is unloaded
     */
    public void destroyApp(boolean unconditional) {
        //clear everything
        mainscreen=null;
        okCommand = null;
        exitCommand = null;
        display=null;
    }

    public void commandAction(Command c, Displayable d) {
	if(c==okCommand) {  
	}
	else if(c==exitCommand) {
	    destroyApp(true);
	    notifyDestroyed();
	}
    }
	
    public void itemStateChanged(Item item) {
	if(item==mainscreen.get(0)) {//option for setting gauge
	    ChoiceGroup c= (ChoiceGroup) item; 
	    if(c.getString(c.getSelectedIndex()).equals("interactive")) {
                System.out.println("Switch to interactive gauge.");
	        mainscreen.delete(mainscreen.size()-1);
		mainscreen.append(new Gauge("Gauge Test",true,100,50));				
	    }
	    else if(c.getString(c.getSelectedIndex()).equals("noninteractive")) {
                System.out.println("Switch to non-interactive gauge.");
		mainscreen.delete(mainscreen.size()-1);
		mainscreen.append(new Gauge("Gauge Test",false,100,50));
	    }
	}
        else if(item==mainscreen.get(1)) {//textfield
	    TextField tf= (TextField) item; 
            System.out.println("textfield: "+tf.getString());
	    int value=Integer.parseInt(tf.getString());
            Gauge g= (Gauge)mainscreen.get(mainscreen.size()-1);
	    g.setValue(value);   
	}
    }
}

⌨️ 快捷键说明

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