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

📄 splash.java

📁 很不错的泡泡堂手机游戏
💻 JAVA
字号:
/*
 * 创建日期 2007-2-20 @author cpiz
 * 
 * Splash画面
 */
package com.cpiz.poptang;

import java.util.Timer;
import java.util.TimerTask;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class Splash extends Canvas
{
    PopTang midlet = null;
   
    Timer timer = null;

    /**
     * 构造函数
     * 
     * @param midlet
     *            父MIDlet对象
     */
    public Splash(PopTang midlet)
    {
        this.midlet = midlet;
    }
    
    public void showMe()
    {
        // 使用MIDP2.0自带的全屏模式
        this.setFullScreenMode(true);

        // 初始化计时器,一定时间后跳转至游戏菜单
        timer = new Timer();
        timer.schedule(new TimerTask()
        {
            public void run()
            {
                showNextScreen();
            }
        }, PopTang.SPLASH_TIME);
        
        midlet.setDisplayable(this);
    }

    /**
     * 显示下一屏
     */
    private void showNextScreen()
    {
        timer.cancel();
        timer = null;
        midlet.menu.showMe();
    }

    /**
     * 清除屏幕
     * @param g 屏幕对象
     */
    private void clearGraphics(Graphics g)
    {
        int lastColor = g.getColor();
        g.setColor(0xFFFFFF);// 默认清理为白色
        g.fillRect(0, 0, getWidth(), getHeight());
        g.setColor(lastColor);
    }
    
    protected void paint(Graphics g)
    {
        clearGraphics(g);
        
        try
        {
            // 在屏幕中央绘制splash图片
            g.drawImage(Image.createImage("/img/splash.png"),
                    (getWidth() - PopTang.GAME_WIDTH) / 2,
                    (getHeight() - PopTang.GAME_HEIGHT) / 2, 
                    Graphics.LEFT | Graphics.TOP);
            
            // 设置字体
            g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
                    Font.SIZE_SMALL));

            // 在屏幕左上方绘制版本号            
            g.drawString(
                    "v" + midlet.getAppProperty("MIDlet-Version"), 
                    0, 
                    0, 
                    Graphics.LEFT | Graphics.TOP);
            
            // 在屏幕右下方绘制skip提示            
            g.drawString(PopTang.SKIP_SPLASH_TIP, getWidth() - 2, getHeight() - 2,
                    Graphics.RIGHT | Graphics.BOTTOM);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }

    /**
     * 处理按键事件
     */
    protected void keyPressed(int keyCode)
    {
        // 按任意键进入菜单
        showNextScreen();
    }
}

⌨️ 快捷键说明

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