一、原理
圆弧的2个角度,一个角度是圆弧的起始点,另一个角度是圆弧的终点。在一个钟表上,3点的位置是0度,当逆时针方向移动时,度数会增加,12点是90度,当顺时针方面移动时,度数会减少。
二、图
三、代码
Midlet.java
package test;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Midlet extends MIDlet {
privateDisplay display;
privateMIDPCanvas midpcanvas;
publicMidlet(){
display=Display.getDisplay(this);
midpcanvas=new MIDPCanvas(this);
}
public voidstartApp() {
display.setCurrent(midpcanvas);
}
publicvoid pauseApp() {
}
public voidexitMIDlet() {
destroyApp(true);
notifyDestroyed();
}
public voiddestroyApp(boolean unconditional) {
}
}
MIDPCanvas.java
package test;
import javax.microedition.lcdui.*;
public class MIDPCanvas extends Canvas implements CommandListener{
privateCommand cmd_exit;
private Midlet midlet;
publicMIDPCanvas(Midlet midlet) {
try {
// Set up this canvas to listen to command events
this.midlet=midlet;
cmd_exit=new Command("退出",Command.EXIT,1);
addCommand(cmd_exit);
setCommandListener(this);
} catch(Exception e) {
e.printStackTrace();
}
}
public voidpaint(Graphics g) {
g.setColor(255,255,255);
g.fillRect(0,0, getWidth(), getHeight());
g.setColor(0,255,0);
g.drawArc(0, 0, getWidth(), getHeight(), 180, 180);
}
protected void keyPressed(int keyCode) {
}
protected void keyReleased(int keyCode) {
}
protected void keyRepeated(int keyCode) {
}
protected void pointerDragged(int x, int y){
}
protected void pointerPressed(int x, int y){
}
protected void pointerReleased(int x, int y){
}
public voidcommandAction(Command command, Displayable displayable) {
if (command==cmd_exit){
midlet.exitMIDlet();
}
}
}