📄 trianglefillarcmidlet.java~7~
字号:
package trianglefillarc;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class triangleFillArcMIDlet extends MIDlet implements Runnable{
static triangleFillArcMIDlet instance;
triangleFillArcCanvas ciCanvas;
Thread thread;
int count=0;
public triangleFillArcMIDlet() {
instance = this;
ciCanvas = new triangleFillArcCanvas(150,150,0,0X00F30EF6);
thread = new Thread(this);
}
public void startApp() {
Display.getDisplay(this).setCurrent(ciCanvas);
thread.start();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public static void quitApp() {
instance.destroyApp(true);
instance.notifyDestroyed();
instance = null;
}
public void run(){
while(count<100){
count=count+1;
try{
thread.sleep(50);
}catch(InterruptedException e){}
ciCanvas.setValue(count);
ciCanvas.repaint();
}
}
}
class triangleFillArcCanvas extends Canvas implements CommandListener{
private final static int maxValue=100;
int width,height;
int nowValue,stepValue;
Font perFont;
int fontWidth;
int style;
int color;
Command restartCmd,quitCmd;
public triangleFillArcCanvas(int width,int height,int style,int color){
this.width=width;
this.height=height;
this.style=style;
this.color=color;
perFont=Font.getFont(Font.FACE_PROPORTIONAL,
Font.STYLE_BOLD,Font.SIZE_LARGE);
restartCmd = new Command("重新演示",Command.SCREEN,0);
quitCmd = new Command("退出程序",Command.EXIT,1);
this.addCommand(restartCmd);
this.addCommand(quitCmd);
this.setCommandListener(this);
}
public void setValue(int value){
nowValue=value;
}
public int getValue(){
return nowValue;
}
protected void paint(Graphics g){
int x=0,y=0;
if(width>this.getWidth()){
width=this.getWidth();
}
if(height>this.getHeight()){
height=this.getHeight();
}
x=(this.getWidth()-width)/2;
y=(this.getHeight()-height)/2;
stepValue=360/maxValue+1;
g.setColor(0X000000FF);
g.fillTriangle(getWidth()/2,getHeight()/2,
0,getHeight(),getWidth(),getHeight());//正三角
g.setColor(0X0000FF00);
g.fillTriangle(this.getWidth()/2,this.getHeight()/2,
0,0,this.getWidth(),0);
g.setColor(0X00FF0000);
g.fillTriangle(this.getWidth()/2,this.getHeight()/2,
0,0,0,this.getHeight());
g.setColor(0X00FFCC00);
g.fillTriangle(this.getWidth()/2,this.getHeight()/2,
this.getWidth(),0,this.getWidth(),this.getHeight());
g.setColor(color);
if(style>0){
stepValue=0-stepValue;
}
g.fillArc(x,y,width,height,0,nowValue*stepValue);
g.setColor(0X00DBF582);
g.fillArc(x+width/4,y+height/4,width/2,height/2,0,360);
g.setColor(0X00000000);
fontWidth=perFont.stringWidth(""+nowValue+"%");//把分值转化为百分数
g.setFont(perFont);
g.drawString(""+nowValue+"%",
x+width/4+(width/2-fontWidth)/2,
y+height/4+(height/2-perFont.getHeight())/2,
g.TOP|g.LEFT);
}
public void commandAction(Command c,Displayable d){
if(c==restartCmd) {
style=0;
triangleFillArcMIDlet.instance.thread.start();
repaint();
}
if(c==quitCmd){
triangleFillArcMIDlet.quitApp();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -