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

📄 harddrivemidlet.java

📁 it is a 2d game example
💻 JAVA
字号:
/* HardDriveMIDlet.java : Container MIDlet */

import java.io.IOException;
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;

public class HardDriveMIDlet 
extends MIDlet 
implements CommandListener
{
 
	private Display dgDisplay;
	private HardDriveCanvas hdCanvas;
	private GameOverCanvas goCanvas;

	static final Command ExitCommand = new Command("Exit", Command.EXIT, 0); 
	
	public HardDriveMIDlet( ) 
	{ // Create the main Display 
		dgDisplay = Display.getDisplay(this); 
	} 

	protected void startApp() //throws MIDletStateChangeException 
	{
		try{
			hdCanvas = new HardDriveCanvas(this, "/car.png", "/obstacle.png");
			hdCanvas.start();
			hdCanvas.addCommand(ExitCommand);
			hdCanvas.setCommandListener(this);
			}
		catch (IOException ioe) 
		{
			System.err.println("Problem loading image "+ioe);
		}
//Set newly created canvas as current canvas
				dgDisplay.setCurrent(hdCanvas);
	}

	public void pauseApp() 
	{
	}

	public void destroyApp(boolean unconditional) 
	{
			hdCanvas.stop();
	}
	public void commandAction(Command c, Displayable s)
	{
		if (c.getCommandType( ) == Command.EXIT) 
		{
			destroyApp(true);
			notifyDestroyed( );
		}
	}

	public void HardDriveCanvasGameOver(long time, int score)
	{
		hdCanvas.stop();
		try
		{
		goCanvas = new GameOverCanvas(this, time, score);
		goCanvas.start();
		
            //Command quitCommand = new Command("Quit", Command.EXIT, 1); 
		goCanvas.addCommand(ExitCommand);
		goCanvas.setCommandListener(this);
				
		}
		catch (Exception exp) 
		{
			System.err.println("Problem loading image "+exp);
		}

        	dgDisplay.setCurrent(goCanvas);
	}	

}  //end of class HardDriveMIDlet

/*Creating project "HardDriveGame" Place Java source files in "C:\WTK21\apps\HardDriveGame\src" Place *application resource files in "C:\WTK21\apps\HardDriveGame\res" Place application library files in *"C:\WTK21\apps\HardDriveGame\lib" Settings updated Project settings saved*/

⌨️ 快捷键说明

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