colortest.java~1~

来自「java教程第八章事例」· JAVA~1~ 代码 · 共 83 行

JAVA~1~
83
字号
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class ColorTest extends MIDlet implements CommandListener, ItemStateListener{

	Display display;
	Form form;
	Gauge red, green, blue;
	MyCanvas myCanvas;
	Command exitCmd;
	Command okCmd;

	public ColorTest(){
		display = Display.getDisplay(this);
		form = new Form("砞﹚肅︹");
		red = new Gauge("Red:0", true, 255, 0);
		green = new Gauge("Green:0", true, 255, 0);
		blue = new Gauge("Blue:0", true, 255, 0);
		myCanvas = new MyCanvas(form);
		exitCmd = new Command("瞒秨", Command.EXIT, 1);
		okCmd = new Command("絋﹚", Command.OK, 1);
		form.append(red);
		form.append(green);
		form.append(blue);
		form.addCommand(exitCmd);
		form.addCommand(okCmd);
		form.setCommandListener(this);
		form.setItemStateListener(this);

	}


	public void startApp(){
		display.setCurrent(form);
		
	}

	public void pauseApp(){
		
	}

	public void destroyApp(boolean unconditional){
		
	}
	
	public void commandAction(Command c, Displayable d){
		if(c == exitCmd){
			destroyApp(true);
			notifyDestroyed();
		}
		else if(c == okCmd){
			int r = (red.getValue() & 0xff);
			int g = (green.getValue() & 0xff);
			int b = (blue.getValue() & 0xff);
			myCanvas.rgb = (r << 16)| (g << 8) | b;
			display.setCurrent(myCanvas);
		}	
	}
	
	public void itemStateChanged(Item item){
		
		if(item == red){
			red.setLabel("Red:"+red.getValue());
		}
		else if(item == green){
			green.setLabel("Green:"+green.getValue());
		}
		else if(item == blue){
			blue.setLabel("Blue:"+blue.getValue());
		}	
		
	}

	class MyCanvas extends Canvas implements CommandListener{

		int rgb;
		Displayable previousScreen;
		Command backCmd;
	
		public MyCanvas(Displayable d){
			previousScreen = d;
			rgb =0;
			backCmd = new Command("

⌨️ 快捷键说明

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