📄 waitcanvas.java
字号:
package com.j2medev.chapter3;
import javax.microedition.lcdui.*;
public class WaitCanvas extends Canvas implements CommandListener,Runnable{
private int percent = 0;
private int height = 15;
private int dert = 0;
private int x = 0;
private boolean stop = false;
private Command cancel = new Command("Cancel",Command.CANCEL,1);
public WaitCanvas() {
dert = getWidth()/10;
x = (getWidth()-10*dert)/2;
addCommand(cancel);
setCommandListener(this);
new Thread(this).start();
}
public void paint(Graphics g){
int color = g.getColor();
g.setColor(0xFFFFFF);
g.fillRect(0,0,getWidth(),getHeight());
g.setColor(255,0,0);
g.drawRoundRect(x,getHeight()/2,10*dert,height,2,2);
g.setColor(0x6699cc);
g.fillRoundRect(x+1,getHeight()/2+1,dert*percent-1,height-1,2,2);
}
public void run(){
while(!stop){
percent++;
repaint();
try{
Thread.sleep(200);
}catch(InterruptedException ex){
}
if(percent == 10){
stop = true;
Alert alert = new Alert("Finished","The article has been posted!",null,AlertType.INFO);
alert.setTimeout(2000);
StackMIDlet.moveNext(alert,new MainMenu());
}
}
}
public void commandAction(Command cmd,Displayable displayable){
if(cmd == cancel){
stop = true;
StackMIDlet.goBack();
}else if(cmd.getCommandType() == Command.EXIT){
StackMIDlet.handleCommandAction(cmd,displayable);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -