类似于推箱子的手机游戏源码

源代码在线查看: splash.java

软件大小: 2730 K
上传用户: gjinli88
关键词: 手机游戏 源码
下载地址: 免注册下载 普通下载 VIP

相关代码

				import javax.microedition.lcdui.Canvas;
				import javax.microedition.lcdui.Font;
				import javax.microedition.lcdui.Graphics;
				import javax.microedition.lcdui.Image;
				/*
				 * Splash.java
				 *
				 * Created on 2007年10月19日, 下午3:10
				 *
				 * To change this template, choose Tools | Template Manager
				 * and open the template in the editor.
				 */
				
				/**
				 *
				 * @author liang
				 */
				public class Splash extends Canvas implements Runnable{
				    
				    /** Creates a new instance of Splash */
				    private final Hunt_Midlet midlet;                     //主类
				    private Image splashImage;                          //游戏闪屏图片(100*53)
				    private volatile boolean dismissed = false;       //是否消除闪屏
				    //此处volatile使dismissed的状态一旦改变,立即响应
				    
				    /** Creates a new instance of SplashScreen */
				    public Splash(Hunt_Midlet midlet) {
				        this.midlet = midlet;
				        setFullScreenMode(true);                            //设置为全屏模式
				        splashImage = ImageTools.createImage("/splash.png"); //加载闪屏图片
				        new Thread(this).start();                           //开启闪屏线程
				    }
				    
				    public void run(){  
				        synchronized(this){   //此处加同步锁的作用是防止此线程在wait(4000L)时,其它线程启动
				            try{
				                wait(3000L);                                //显示4秒
				            }catch(InterruptedException e){}
				            dismiss();                                      //消除闪屏
				        }
				    }
				    
				    public void paint(Graphics g){
				        int CanvasWidth = getWidth();
				        int CanvasHeight = getHeight();
				        g.setColor(0x00000000);                         //画笔颜色
				        g.fillRect(0,0,getWidth(), getHeight());      //填充屏幕
				        if(splashImage != null){
				            g.drawImage(splashImage, CanvasWidth/2, CanvasHeight/2-20,
				                        Graphics.VCENTER|Graphics.HCENTER);
				            splashImage = null;                         //释放图片资源用于垃圾回收
				        }   
				        g.setColor(0x00969696);
				        g.setFont(Font.getFont(Font.FACE_PROPORTIONAL,Font.STYLE_BOLD,Font.SIZE_LARGE));
				        g.drawString("小胖工作组", CanvasWidth/2, CanvasHeight/2+18, Graphics.HCENTER|Graphics.TOP);
				        midlet.splashScreenPainted();                  //告知主类闪屏绘制完毕可以开始初始化
				    }
				    
				    public synchronized void keyPressed(int keyCode){//
				        dismiss();                                      //按下任意键取消闪屏
				    }
				    /** 取消闪屏 */
				    public void dismiss(){
				        if(!dismissed){
				            dismissed = true;
				            midlet.splashScreenDone();                 //取消闪屏,告知主类显示菜单
				        }
				    }    
				}
				
				    
							

相关资源