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

📄 splash.java

📁 J2ME Game Programming的隋书源代码
💻 JAVA
字号:
//#ifdef nokia

import com.nokia.mid.ui.FullCanvas;
//#endif
import javax.microedition.lcdui.*;

//#ifdef nokia

public class Splash extends FullCanvas implements Runnable

//#else
//# 
//# public class Splash extends Canvas implements Runnable
//#endif
{
   private boolean running = true;
   private Image osb;
   private Graphics osg;
   private StarAssault theMidlet;
   private int starFieldViewY;
   private Image title;
   private int fontHeight;
   private Font font;

   public Splash(StarAssault midlet)
   {
      theMidlet = midlet;
      initResources();

      // create the timer thread
      Thread t = new Thread(this);
      t.start();
   }

   private void initResources()
   {
      // setup the screen
      osb = Image.createImage(getWidth(), getHeight());
      osg = osb.getGraphics();

      title = ImageSet.loadClippedImage("/splash.png", 0, 0);
      font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
      fontHeight = font.getHeight() + 2;

      osg.setFont(font);
   }

   private static final int MAX_CPS = 100;
   private static final int MS_PER_FRAME = 1000 / MAX_CPS;

   public void run()
   {
      try
      {
         while (running)
         {
            // remember the starting time
            long cycleStartTime = System.currentTimeMillis();

            // do our work
            repaint();

            // sleep if we've finished our work early
            long timeSinceStart = (cycleStartTime - System.currentTimeMillis());
            if (timeSinceStart < MS_PER_FRAME)
            {
               try
               {
                  Thread.sleep(MS_PER_FRAME - timeSinceStart);
               }
               catch (java.lang.InterruptedException e)
               {
               }
            }
         }

         // fall back to the splash form at the end of our loop
         theMidlet.activateMenu();
      }
      catch (Exception e)
      {
         System.out.println("App exception: " + e);
         e.printStackTrace();
      }

   }

   private void renderSplash()
   {
      // clear the background
      osg.setColor(0);
      osg.fillRect(0, 0, getWidth(), getHeight());

      // draw a moving starfield
      if (starFieldViewY++ > 128) starFieldViewY = 0;
      Tools.drawStarField(osg, 0, starFieldViewY, getWidth(), getHeight());

      osg.drawImage(title, getWidth() / 2, getHeight() / 2 - 10, Graphics.HCENTER | Graphics.VCENTER);

      // draw text
      osg.setColor(0x00888888);
      osg.drawString(Locale.getString("Application.Copyright"), getWidth() / 2, getHeight() - fontHeight * 3,
                     Graphics.HCENTER | Graphics.TOP);
      osg.drawString(Locale.getString("Application.Author"), getWidth() / 2, getHeight() - fontHeight * 2,
                     Graphics.HCENTER | Graphics.TOP);
      // draw the copy line
      osg.setColor(0x00ffffff);
      osg.drawString(Locale.getString("Application.Press key"), getWidth() / 2, getHeight() - fontHeight * 1,
                     Graphics.HCENTER | Graphics.TOP);
   }

   protected void paint(Graphics graphics)
   {
      renderSplash();
      graphics.drawImage(osb, 0, 0, Graphics.LEFT | Graphics.TOP);
   }

   protected void keyPressed(int keyCode)
   {
      running = false;
   }
}


⌨️ 快捷键说明

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