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

📄 ncuscsplash.java

📁 很不错的泡泡堂手机游戏
💻 JAVA
字号:
/*
 * 创建日期 2007-2-20 @author cpiz
 * 由源码爱好者_www.codefans.net整理下载
 * 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 NcuscSplash extends Canvas
{
    PopTang midlet = null; 
    
    Timer timer = null;

    /**
     * 构造函数
     * 
     * @param midlet
     *            父MIDlet对象
     */
    public NcuscSplash(PopTang midlet)
    {
        this.midlet = midlet;
    }

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

    /**
     * 在屏幕上显示自身
     */
    protected void showMe()
    {
        // 使用MIDP2.0自带的全屏模式
        this.setFullScreenMode(true);        

        // 初始化计时器,一定时间后跳转至游戏菜单
        timer = new Timer();
        timer.schedule(new TimerTask()
        {
            public void run()
            {
                showNextScreen();
            }
        }, PopTang.SPLASH_TIME);
        
        midlet.setDisplayable(this);
    }
    
    /**
     * 清除屏幕
     * @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
        {
            // 绘制坐标点
            int x = 0;
            int y = 0;
            int splashHeight = 0;

            Image imgNcuName = null;
            Image imgNcuLogo = null;

            Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
                    Font.SIZE_SMALL);
            
            // 检测屏幕高度以设置垂直居中
            if (getHeight() > 128)
            {
                imgNcuName = Image.createImage(PopTang.IMAGE_SRC_NCUNAME);
                imgNcuLogo = Image.createImage(PopTang.IMAGE_SRC_NCULOGO);
            
                splashHeight = imgNcuName.getHeight() + imgNcuLogo.getHeight()
                        + PopTang.SPLASH_ROW_SPACING * 4 + font.getHeight() * 4;
            }// 屏高大于128则绘制logo
            else
            {
                imgNcuName = Image.createImage(PopTang.IMAGE_SRC_NCUNAME);                
            
                splashHeight = imgNcuName.getHeight()
                        + PopTang.SPLASH_ROW_SPACING * 4 + font.getHeight() * 4;
            
            }// 屏高小于128则仅绘制"南昌大学"文字
            
            // 计算y轴起始绘制位置
            x = getWidth() / 2;
            y = (getHeight() - splashHeight) / 2;
            
            // 绘制"南昌大学"名称            
            g.drawImage(imgNcuName, x, y, Graphics.HCENTER | Graphics.TOP);
            y += imgNcuName.getHeight() + PopTang.SPLASH_ROW_SPACING;
            
            // 绘制南昌大学Logo
            if(imgNcuLogo != null)
            {
                g.drawImage(imgNcuLogo, x, y, Graphics.HCENTER | Graphics.TOP);
                y += imgNcuLogo.getHeight() + PopTang.SPLASH_ROW_SPACING;
            }
            
            for(int i = 0; i < PopTang.SPLASH_TEXT.length; i++)
            {
                if(i % 2 == 0)
                {
                    g.setColor(0xFF0000);
                }
                else
                {
                    g.setColor(0x0000FF);
                }
                
                g.drawString(PopTang.SPLASH_TEXT[i], x, y, Graphics.HCENTER | Graphics.TOP);
                y += font.getHeight() + PopTang.SPLASH_ROW_SPACING;
            }
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }

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

⌨️ 快捷键说明

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