基于Nokia S40的猜数字游戏之二[2]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

public abstract class NumScreen extends FullCanvas
{
    protected Timer timer = new Timer();
    protected Display display;
    protected Manager next;
    protected int timeout;
    protected Font font;
   
    public NumScreen(Display display,Manager next)
    {
        this.display = display;
        this.next = next;

        setTimeout(3000);
    }
   
    public Font getFont()
    {
        if(font == null)
        {
            font = Font.getDefaultFont();
        }
        return font;
    }
   
    public void setFont(Font font)
    {
        this.font = font;
    }
   
    public void setTimeout(int time)
    {
        this.timeout = time;
    }
   
   
    public void dismiss()
    {
        timer.cancel();
        display.setCurrent(next);
    }
   
    public void showNotify()
    {
        timer.schedule(new TimerTask()
                {
              public void run()
              {
                  dismiss();
              }
                },3000);
    }
   
}
基于这个类,我们实现一个SplashScreen用在程序启动的时候的欢迎界面上,还提供一个类CongScreen用于显示用户的成绩和提示。

package com.j2medev.numbergame;

import java.io.IOException;

import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class SplashScreen extends NumScreen
{

    public SplashScreen(Display display,Manager next)
    {
        super(display, next);
    }

    protected void paint(Graphics arg0)
    {
        Image welcome = null;
        try
        {
            welcome = Image.createImage("/welcome.png");
        } catch (IOException e)
        {
            e.printStackTrace();
        }

        arg0.drawImage(welcome, 2, 2, Graphics.TOP | Graphics.LEFT);
       

    }
   

}


package com.j2medev.numbergame;

import java.io.IOException;

import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class CongScreen extends NumScreen
{

    private String title;

    private Mark mark;

    private Image image;
   
    private Image star;
   
    private Manager manager;
   
    private int type = CONG;
   
    public static final int CONG = 1;
    public static final int WARNING = 2;

    public CongScreen(Display display, Manager next)
    {
        super(display, next);
       
    }

本文关键:基于Nokia S40的猜数字游戏之二
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top