正文

J2ME @J2ME计时器@2006-11-22 10:12:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/sword2008/20594.html

分享到:

/*

*http://blog.programfan.com/blog.asp?author=qq14923349

*程序之巢制作 @J2ME计时器@

*如果有图片

*图片存在rec目录下,记得在存之前把格式转换成png,具体方法是:

1,点击开始

2,附件

3,图画板

4,打开图片

5,另存为(可以存作PNG了,不要直接改后续名,否则运行不了)

6,其他工具,可以选用PS,或者ACDSEE等等改

*/


import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.*;
import java.util.*;

public class Hourmeter extends MIDlet
{
 
 
 public void startApp(){
 
 new Count(Display.getDisplay(this)).start();
         }

 public void pauseApp(){}

 public void destroyApp(boolean e){}


 class Count extends GameCanvas implements Runnable{
 
 private Display display;
 private Random rand;
 private boolean Runonce=true;
 private int hour,minute,second;//当前时间
 private int X,Y=60;//移动框
 private int sign=1;//当前第几个框
 private boolean once=true;//第一次画屏
 private Calendar calendar;
 private boolean down3=false;//第三个框给按下

 public Count(Display d){

 super(true);
 
 display=d;
 
 display.setCurrent(this);
         }

 

 private void start(){
 try{
 rand=new Random();
 
    }
 catch(Exception e){
     }
 
 Thread t=new Thread(this);
 t.start();

       }

 


 public void run(){
 Graphics g=getGraphics();

 while(Runonce){
 update();
 
 timeCount();

 g=timeRect();

 draw(g);
 
 
 
 try{
 Thread.sleep(100);
 
    }
 catch(Exception e){}
     }
    }

 private void update()
 {
 
 
 int keyState=getKeyStates();
 
 if((keyState&LEFT_PRESSED)!=0)
 {

 }
 else if((keyState&RIGHT_PRESSED)!=0)
 {

 }
 if((keyState&FIRE_PRESSED)!=0)
 {
 switch(sign)
 {
 case 1:System.out.println("你选择了1");break;
 case 2:System.out.println("你选择了2");break;
 case 3:introductory();down3=!down3;break;
 default:;
 }
 
 }
 if((keyState&UP_PRESSED)!=0)
 {
 Graphics g=getGraphics();
 g.setColor(0xff0000);
 g.fillRect(0,Y,60,20);
 
 if(Y==60)
 {draw(g);
 
 }
 else
 {
 Y-=20;
 sign-=1;
 System.out.println(sign);
 draw(g);
 }
 }
 if((keyState&DOWN_PRESSED)!=0)
 {
 Graphics g=getGraphics();
 g.setColor(0xff0000);
 g.fillRect(0,Y,60,20);
 
 if(Y==100)
 draw(g);
 else{
 Y+=20;
 sign+=1;
 System.out.println(sign);
 draw(g);
     }
 }
 
 }
//--------------------------------
 private void timeCount(){
 calendar=Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00"));
 hour=calendar.get(Calendar.HOUR_OF_DAY);
 minute=calendar.get(Calendar.MINUTE);
 second=calendar.get(Calendar.SECOND);

    }
//--------------------------------
 private Graphics timeRect(){
 Graphics g=getGraphics();
 
 g.setColor(0x008800);
 g.fillRect(0,60,60,60);
 g.setColor(0x000000);
 g.drawRect(0,60,60,20);
 g.drawRect(0,60,60,40);
 g.drawRect(0,60,60,60);

 g.setColor(0x0000ff);
    g.drawString("  计时开始",0,60,Graphics.TOP|Graphics.LEFT);
 g.drawString("  计时停止",0,80,Graphics.TOP|Graphics.LEFT);
 g.drawString("  关    于",0,100,Graphics.TOP|Graphics.LEFT);
 
 if(down3==true)
 introductory();
 
 return g;
 
              }

//--------------------------------
 private void introductory(){

 Graphics g=getGraphics(); 
 g.setFont(Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN,Font.SIZE_SMALL));
 g.setColor(0x00ff00);
 g.drawString("本程序由剑2008制作",20,60,Graphics.TOP|Graphics.LEFT);
 g.drawString("qq14923349",20,80,Graphics.TOP|Graphics.LEFT);

 g.drawString("v1.0版本",20,100,Graphics.TOP|Graphics.LEFT);

       }
//--------------------------------
 private void draw(Graphics g){

 
 if(once==true){
 g.setColor(0xffffff);
 g.fillRect(0,0,getWidth(),getHeight()); 

 g.setColor(0x000000);
 g.drawString("@J2ME计时器@",20,20,Graphics.TOP|Graphics.LEFT);
 g.drawString(""+hour+" : "+minute+" : "+second,10,40,Graphics.TOP|Graphics.LEFT);
 once=false;
  }
 else
 {g.setColor(0xffffff);
 g.fillRect(10,40,120,20);
 g.setColor(0x000000);
 g.drawString("@J2ME计时器@",20,20,Graphics.TOP|Graphics.LEFT);
  g.drawString(""+hour+" : "+minute+" : "+second,10,40,Graphics.TOP|Graphics.LEFT);
 }
 

 flushGraphics();
         }

 
               }

}

 

阅读(5428) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册