⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trianglefillarcmidlet.java~14~

📁 这是在学习交j2me时做的一个小程序
💻 JAVA~14~
字号:
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){
     g.setColor(255,255,255);
     g.fillRect(0,0,this.getWidth(),this.getHeight());
     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) {
        if(style <1)
        style=1;
        else
          style=0;
        stepValue = 0;
        repaint();
      }
      if(c==quitCmd){
        triangleFillArcMIDlet.quitApp();
      }
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -