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

📄 racermidlet.java

📁 Programming java 2 microedition symbian os一书中作者编写的一个赛车游戏的半成品
💻 JAVA
字号:
/*
 * Copyright 2003, 2004 Symbian Ltd.
 * For License terms see http://www.symbian.com/developer/techlib/codelicense.html
 */

package demoracer;

/**
 * <p>Title: DemoRacer</p>
 * <p>Description: Game API Demo for Symbian MIDP 2.0 Book.</p>
 * @author Alan Newman - alan@sensibledevelopment.net
 * @version 1.0
 */


/*
 * The MIDlet class for the application.
 * this basically gets the displayable object - the RacerCanvas
 * and makes it the current display.
 */
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.io.IOException;

public class RacerMidlet extends MIDlet{
    
    private RacerGameCanvas gameCanvas;
    private Display display;
    private Displayable displayable;
    
    public RacerMidlet() {
        // get the current display context.
        display = Display.getDisplay(this);
    }
    
    protected void startApp(){
        // get the Canvas and then set it as he current display
        try {
            getCanvasDisplay();
            display.setCurrent(displayable);
        }catch(Exception e) {
            Alert alert = new Alert("Error", e.getMessage(), null, AlertType.ERROR);
            display.setCurrent(alert);
            try {
                Thread.sleep(2000);
            }catch (InterruptedException ie) {
                
            }
            notifyDestroyed();
        }
    }
    
    protected void pauseApp() {
        // if a the MIDlet needs to paused then this method will be called.
        // release resources to free up memory for other processes.
        if(displayable!=null) {
            display.setCurrent(displayable);
        }
        releaseResource();
    }
    
    protected void destroyApp(boolean unconditional) {
        // exit the MIDlet
        releaseResource();
    }
    
    // this is called by the pauseApp() method. Stop the canvas to release resource
    public void releaseResource() {
        if(gameCanvas!=null) {
            gameCanvas.stop();
        }
    }
    
    /* This method is called by startApp().
     * it assumes that startApp() can be called more than once during the lifecycle of the MIDlet.
     * therefore it checks to see if the canvas has been created and takes action accordingly. This prevents multiple
     * instances of the canvas being created by startApp()
     */
    private void getCanvasDisplay() throws Exception{
        try{
            // if there is no canvas then create one
            if(gameCanvas==null) {
                gameCanvas=new RacerGameCanvas(this);
            }
            // if the canvas is not running then start it
            if(!gameCanvas.isRunning()) {
                gameCanvas.start();
            }
            //set the canvas as the "global" displayable object
            displayable=gameCanvas;
        }catch(IOException ioe) {
            throw new Exception("Unable to load image!!");
        }
    }
    
}

⌨️ 快捷键说明

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