?? main.java
字號:
?import javax.microedition.midlet.*;
/**
* <p>
* Title:
* </p>
* <p>
* Description:
* </p>
* <p>
* Copyright: Copyright (c) 2005
* </p>
* <p>
* Company:
* </p>
* 非作者授權,請勿用于商業用途。
* @author bruce.fine@gmail.com
* @version 1.0
*/
import javax.microedition.lcdui.*;
public final class Main extends MIDlet implements Runnable {
//
// 本身引用
static Main s_instance;
// 記錄fps值
static int nFps = 0;
private long nnRuntime = 0;
private int nFrames = 0;
private long nnStartTime = 0;
// 游戲界面
private MyGameCanvas myGameCanvas = null;
// 系統事件處理
static boolean isAppPaused = false;
static boolean isLooping = true;
static String strVersion = "1.0";
static boolean isSoundOn = false;
static boolean isMIDletStarted = false;
Thread thread = null;
//
// 構造
public Main() {
}
// 暫停
final protected void pauseApp() {
isAppPaused = true;
} // void pauseApp()
// 開始
final protected void startApp()
throws javax.microedition.midlet.MIDletStateChangeException {
if (!isMIDletStarted) {
isMIDletStarted = true;
s_instance = this;
try {
strVersion = getAppProperty("MIDlet-Version");
} // try
catch (Exception ex) {
ex.printStackTrace();
} // catch
RMSSystem.init();
isSoundOn = RMSSystem.isSoundOn();
myGameCanvas = new MyGameCanvas();
RMSSystem.getBackId();
Display.getDisplay(s_instance).setCurrent(myGameCanvas);
thread = new Thread(s_instance);
thread.start();
}
} // void startApp()
// 銷毀
final protected void destroyApp(boolean parm1)
throws javax.microedition.midlet.MIDletStateChangeException {
/** @todo Implement this javax.microedition.midlet.MIDlet abstract method */
myGameCanvas = null;
} // void destroyApp
/**
* Implement of run() method in Runnable interface.
*/
final public void run() {
try {
nnStartTime = System.currentTimeMillis();
// while (gameThread == Thread.currentThread()) {
while (isLooping) {
if (Consts.SIS_SHOW_FPS) {
// 計算FPS
nFrames++;
nnRuntime += System.currentTimeMillis() - nnStartTime;
if (nnRuntime >= 1000) {
nFps = nFrames;
nFrames = 0;
nnRuntime -= 1000;
} // if
} // if
nnStartTime = System.currentTimeMillis();
// if (currCanvas != null && currCanvas.isShown()) {
if (myGameCanvas != null) {
myGameCanvas.tick();
} // if
else {
// System.out.println("Do nothing:)");
} // else
long timeTaken = System.currentTimeMillis() - nnStartTime;
if (timeTaken < Consts.SN_MILLIS_PER_TICK) {
synchronized (this) {
Thread.sleep(Consts.SN_MILLIS_PER_TICK - timeTaken);
} // synchronized
} // if
else {
Thread.yield();
} // else
} // while
if (myGameCanvas != null) {
RMSSystem.saveSound(Main.isSoundOn);
// SOUND
}
myGameCanvas = null;
notifyDestroyed();
} // try
catch (InterruptedException ie) {
ie.printStackTrace();
} // catch
catch (Exception e) {
e.printStackTrace();
} // catch
} // run()
} // class
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -