📄 colortest.java
字号:
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("返回", Command.BACK, 1);
addCommand(backCmd);
setCommandListener(this);
}
public void paint(Graphics g){
g.setColor(rgb);
g.fillRect(0, 0, getWidth(), getHeight());
}
public void commandAction(Command c, Displayable d){
if(c == backCmd){
display.setCurrent(previousScreen);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -