- package game;
- import javax.microedition.lcdui.*;
- public class LogoCanvas extends Canvas implements Runnable
- {
- //display对象
- private Display display;
- //线程
- private Thread thread;
- //图片对象
- private Image image;
- //是否显示文字
- private boolean flag = true;
- //提示文字
- private String info = "按任意键继续...";
- private int logoNum = 0;
- public LogoCanvas(Display display, int logoNum)
- {
- this.display = display;
- this.logoNum = logoNum;
- //设置全屏
- this.setFullScreenMode(true);
- //导入图片
- try
- {
- image = Image.createImage("/res/logo" + logoNum + ".png");
- }
- catch (Exception e)
- {}
- //启动线程
- thread = new Thread(this);
- thread.start();
- }
- protected void paint(Graphics g)
- {
- g.drawImage(image, 0, 0, Graphics.TOP | Graphics.LEFT);
- if (flag)
- {
- g.setColor(0xffffff);
- g.drawString(info, 50, 140, Graphics.LEFT | Graphics.TOP);
- }
- }
- protected void keyPressed(int keyCode)
- {
- //按任意键继续
- thread = null;
- image = null;
- if ( logoNum == 1 )
- {
- display.setCurrent(new LogoCanvas(display, 2));
- }
- else
- {
- //显示游戏菜单界面
- display.setCurrent(new MainMenuCanvas(display));
- }
- }
- public void run()
- {
- //获得当前运行的线程
- Thread curr = Thread.currentThread();
- int i = 0;
- while (curr == thread)
- {
- //暂停0.3秒
- try
- {
- Thread.sleep(300);
- }
- catch (Exception e)
- {}
- //记数
- i++;
- //改变文字显示的状态
- flag = !flag;
- //如果暂停满3秒,则切换屏幕
- if (i == 9)
- {
- thread = null;
- image = null;
- if ( logoNum == 1 )
- {
- display.setCurrent(new LogoCanvas(display, 2));
- }
- else
- {
- //显示游戏菜单界面
- display.setCurrent(new MainMenuCanvas(display));
- }
- }
- //重新绘制
- repaint();
- }
- }
- }