📄 clearscreen.java
字号:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class ClearScreen extends MIDlet implements CommandListener {
private Command exitCommand;
private Command showCommand;
private Command clearCommand;
private ClearScreenCanvas sg;
public ClearScreen() {
exitCommand = new Command("退出", Command.EXIT, 1);
showCommand = new Command("显示", Command.SCREEN, 1);
clearCommand = new Command("清除", Command.SCREEN, 1);
sg = new ClearScreenCanvas();
sg.addCommand(exitCommand);
sg.addCommand(clearCommand);
sg.setCommandListener(this);
}
protected void startApp(){
Display.getDisplay(this).setCurrent(sg);
}
protected void pauseApp() {
}
protected void destroyApp(boolean arg0){
}
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
if (c == showCommand) {
sg.show();
sg.removeCommand(showCommand);
sg.addCommand(clearCommand);
}
if (c == clearCommand) {
sg.clear();
sg.removeCommand(clearCommand);
sg.addCommand(showCommand);
}
}
}
class ClearScreenCanvas extends Canvas{
private boolean cleared = false;//cleared 表示被清除了
protected ClearScreenCanvas(){
cleared = false;
}
protected void paint(Graphics g) {
if(!cleared){
g.setColor(0,0,0);
g.drawString("Hello World", this.getWidth()/2, this.getHeight()/2,
Graphics.BOTTOM|Graphics.HCENTER);
}
else{
g.setColor(255,255,255);
g.fillRect(0,0,getWidth(),getHeight());
cleared = true;
}
}
public void clear(){
cleared = true;
repaint();
}
public void show(){
cleared = false;
repaint();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -