SplashScreen.java
资源名称:J2ME&Game.rar [点击查看]
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:3k
源码类别:
J2ME
开发平台:
Java
- import javax.microedition.lcdui.*;
- class SplashScreen extends Canvas implements Runnable
- {
- private final escapeeMIDlet midlet;
- private Image splashImage;
- private volatile boolean dismissed = false;
- SplashScreen( escapeeMIDlet midlet)
- {
- this.midlet = midlet;
- setFullScreenMode(true);
- splashImage = escapeeMIDlet.createImage("/splash.png");
- new Thread(this).start();
- }
- public void run()
- {
- synchronized(this)
- {
- try
- {
- wait(3000L); // 3 seconds
- }
- catch (InterruptedException e)
- {
- // can't happen in MIDP: no Thread.interrupt method
- }
- dismiss();
- }
- }
- public void paint(Graphics g)
- {
- int CanvasWidth = getWidth();
- int CanvasHeight = getHeight();
- g.setColor(0x00FFFFFF); // white
- g.fillRect(0, 0, CanvasWidth, CanvasHeight);
- g.setColor(0x00FF0000); // red
- g.drawRect(1, 1, CanvasWidth-3, CanvasHeight-3); // red border one pixel from edge
- if (splashImage != null)
- {
- g.drawImage(splashImage,
- CanvasWidth/2,
- CanvasHeight/2,
- Graphics.VCENTER | Graphics.HCENTER);
- splashImage = null;
- }
- g.setFont(Font.getFont(Font.FACE_PROPORTIONAL,
- Font.STYLE_BOLD,
- Font.SIZE_LARGE));
- int centerX = CanvasWidth / 2;
- int centerY = CanvasHeight / 2+60;
- g.setColor(0x00FFFFFF); // white
- drawText(g, centerX, centerY - 1);
- drawText(g, centerX, centerY + 1);
- drawText(g, centerX - 1, centerY);
- drawText(g, centerX + 1, centerY);
- g.setColor(0x00000000); // black
- drawText(g, centerX, centerY);
- midlet.splashScreenPainted();
- }
- private void drawText(Graphics g, int centerX, int centerY)
- {
- int fontHeight = g.getFont().getHeight();
- int textHeight = 2 * fontHeight;
- int topY = centerY - textHeight / 2;
- g.drawString("逃亡者游戏",
- centerX,
- topY,
- Graphics.HCENTER | Graphics.TOP);
- g.drawString("版本: " + midlet.getAppProperty("MIDlet-Version"),
- centerX,
- topY + fontHeight,
- Graphics.HCENTER | Graphics.TOP);
- }
- public synchronized void keyPressed(int keyCode)
- {
- dismiss();
- }
- private void dismiss()
- {
- if (!dismissed)
- {
- dismissed = true;
- midlet.splashScreenDone();
- }
- }
- }