📄 enemytest.java
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
* An example that creates a player and enemy ship.
* @author Martin J. Wells
*/
public class EnemyTest extends MIDlet implements CommandListener, Runnable
{
private GameScreen gameScreen;
private Command quit;
private boolean running;
/**
* Constructor for the MIDlet create the GameScreen object, adds a quit
* command and then create a thread to do our cycling and painting.
*/
public EnemyTest()
{
// Construct a canvas
gameScreen = new GameScreen();
// And a way to quit
quit = new Command("Quit", Command.EXIT, 2);
gameScreen.addCommand(quit);
gameScreen.setCommandListener(this);
// Create the game thread.
running = true;
Thread t = new Thread(this);
t.start();
}
/**
* Runnable interface run method that cycles the ships and requests a repaint
* of the Canvas.
*/
public void run()
{
while (running)
{
gameScreen.repaint();
gameScreen.cycle();
try
{
// Simple timing - sleep for 100 milliseconds.
Thread.sleep(100);
}
catch (InterruptedException e)
{
}
}
}
/**
* Handles Application Manager notification the MIDlet is starting (or
* resuning from a pause). In this case we set the canvas as the current
* display screen.
* @throws MIDletStateChangeException
*/
protected void startApp() throws MIDletStateChangeException
{
Display.getDisplay(this).setCurrent(gameScreen);
}
/**
* Handles Application Manager notification the MIDlet is about to be paused.
* We don't bother doing anything for this case.
*/
protected void pauseApp()
{
}
/**
* Handles Application Manager notification the MIDlet is about to be
* destroyed. We don't bother doing anything for this case.
*/
protected void destroyApp(boolean unconditional)
throws MIDletStateChangeException
{
}
/**
* The CommandListener interface method called when the user executes
* a Command, in this case it can only be the quit command we created in the
* consutructor and added to the Canvas.
* @param command The command that was executed.
* @param displayable The displayable that command was embedded within.
*/
public void commandAction(Command command, Displayable displayable)
{
try
{
if (command == quit)
{
running = false;
destroyApp(true);
notifyDestroyed();
}
}
catch (MIDletStateChangeException me)
{
System.out.println(me + " caught.");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -