📄 displaydemo.java
字号:
/*
* DisplayDemo.java
*
* Created on 2005年2月18日, 下午6:47
*/
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
/**
* 演示Display的使用
*/
public class DisplayDemo extends MIDlet
implements CommandListener {
//Display管理
Display display = null;
//Form对象
Form form = new Form("演示Display的使用");
//创建命令按钮
static final Command cmdOpenBackLight =
new Command("打开背光灯", Command.ITEM,1);
static final Command cmdStartVibrate =
new Command("开始振动", Command.ITEM,1);
static final Command cmdCloseBackLight =
new Command("关闭背光灯", Command.ITEM,1);
static final Command cmdStopVibrate =
new Command("停止振动", Command.ITEM,1);
static final Command cmdExit = new Command("退出", Command.STOP, 2);
//构造函数
public DisplayDemo() {
}
/**
* 创建并设置Displayable对象
*/
public void startApp() throws MIDletStateChangeException {
form.addCommand(cmdExit);
form.addCommand(cmdOpenBackLight);
form.addCommand(cmdCloseBackLight);
form.addCommand(cmdStartVibrate);
form.addCommand(cmdStopVibrate);
form.setCommandListener(this);
display = Display.getDisplay(this); //获得当前MIDlet的Display对象
display.setCurrent(form); //设置form对象为当前显示对象
//显示是否支持彩色显示
displayIsColor();
//获取当前设备支持的最大颜色数
displayNumberOfColors();
//显示颜色常量的RGB值
displayColorRGB();
//显示当前设备能支持的Alpha级别
displayAlphaLevel();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
/**
* 处理命令按钮事件
*/
public void commandAction(Command c, Displayable d) {
String label = c.getLabel();
if (label.equals("退出")) {
destroyApp(true);
} else if(label.equals("打开背光灯")) {
display.flashBacklight(40000);
} else if(label.equals("关闭背光灯")) {
display.flashBacklight(0);
} else if(label.equals("开始振动")) {
display.vibrate(40000);
} else if(label.equals("停止振动")) {
display.vibrate(0);
}
}
/**
* 获取当前设备支持的最大颜色数
*/
private void displayNumberOfColors() {
int number = display.numColors();
form.append("当前设备支持的颜色数:" + number);
}
/**
* 显示是否支持彩色显示
*/
private void displayIsColor() {
boolean color = display.isColor();
form.append("当前设备是否支持彩色:" + color);
}
/**
* 显示颜色常量的RGB值
*/
private void displayColorRGB() {
String color;
color = Integer.toHexString(display.getColor(
Display.COLOR_BACKGROUND)).toUpperCase();
form.append("背景颜色:" + color + "\n");
color = Integer.toHexString(display.getColor(
Display.COLOR_BORDER)).toUpperCase();
form.append("边框颜色:" + color + "\n");
color = Integer.toHexString(display.getColor(
Display.COLOR_FOREGROUND)).toUpperCase();
form.append("前景颜色:" + color + "\n");
color = Integer.toHexString(display.getColor(
Display.COLOR_HIGHLIGHTED_BACKGROUND)).toUpperCase();
form.append("高亮的背景颜色:" + color + "\n");
color = Integer.toHexString(display.getColor(
Display.COLOR_HIGHLIGHTED_BORDER)).toUpperCase();
form.append("高亮的边框颜色:" + color + "\n");
color = Integer.toHexString(display.getColor(
Display.COLOR_HIGHLIGHTED_FOREGROUND)).toUpperCase();
form.append("高亮的前景颜色:" + color + "\n");
}
/**
* 显示当前设备能支持的Alpha级别
*/
private void displayAlphaLevel() {
int level = display.numAlphaLevels();
form.append("当前设备能支持的Alpha级别:" + level);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -