作者使用JBuilder里面自带WTK自己下载版本那个默认的模拟器看着实在爽另外Jbuilder X下的WTK也是的版本Jbuilder 的WTK是首先开启Jbuilder建立一个Project 然后填写名字和路径继续 然后选择JDK路径本身已有WTK你可以选择但是你也可以自己选择其他的WTK版本: 点击jdk后面的路径按钮继续: next工程建立完毕接着点击file>New: //jpg>然后在对话框左边选择Micro你就能看到右边出现MIDletDisplayable接上面的:如图示 //jpg>点击MIDlet or Displayable则让你输入MIDlet的名字如图: //jpg>继续下一步让你输入一个Displayable的名字包括类型(formcanvas等)是否自动加载Command等等 //jpg>然后Jbuilder自动生成所需代码以及Jbuilder自加的一些东西你可以添加或修改之这里我将本站一篇关于介绍Gamecanvas的文章的代码拿过来做少量修改作为本文章的一个演示 TestMIDletjava文件: package temps; import javaxmicroeditionmidlet*; import javaxmicroeditionlcdui*; /** * Title: * * Description: * * Copyright: Copyright (c) * * Company: * * @author not attributable * @version */ public class TestMIDlet extends MIDlet { private Display display; public void startApp() { try { display = DisplaygetDisplay(this); Displayable gameCanvas = new Displayable(); gameCanvasstart(); displaysetCurrent(gameCanvas); } catch (Exception ex) { Systemoutprintln(ex); } } public Display getDisplay() { return display; } public void pauseApp() { } public void destroyApp(boolean unconditional) { exit(); } public void exit() { Systemgc(); destroyApp(false); notifyDestroyed(); } } Displayablejava内容: package temps; import javaxmicroeditionlcdui*; import javautilRandom; import javaxmicroeditionlcduigame*; /** * Title: * * Description: * * Copyright: Copyright (c) * * Company: * * @author not attributable * @version */ public class Displayable extends GameCanvas implements Runnable { private boolean isPlay; // Game Loop runs when isPlay is true private long delay; // To give thread consistency private int currentX currentY; // To hold current position of the X private int width; // To hold screen width private int height; // To hold screen height private Random random=new Random(SystemcurrentTimeMillis()); private final int[] sequence={}; private int counter=; private int enemyXenemyY; private int enemyDirect=; private boolean isdown=false; private boolean isalive=true; // Sprites to be used private Sprite playerSprite; private Sprite backgroundSprite; private Sprite enemySprite; // Layer Manager private LayerManager layerManager; // Constructor and initialization public Displayable() throws Exception { super(true); width = getWidth(); height = getHeight(); currentX = width / ; currentY = height / ; enemyX=width/; enemyY=height/; delay = ; Image playerImage=null; Image backgroundImage=null; Image enemy=null; // Load Images to Sprites try { playerImage = ImagecreateImage(/transparentpng); backgroundImage = ImagecreateImage(/backgroundpng); enemy=ImagecreateImage(/framespng); } catch(Exception e) { Systemoutprintln(get Image error!+egetMessage()); } playerSprite = new Sprite(playerImage ); Systemoutprintln(playerSpritegetRawFrameCount()); enemySprite=new Sprite(enemy); backgroundSprite = new Sprite(backgroundImage); layerManager = new LayerManager(); layerManagerappend(playerSprite); layerManagerappend(enemySprite); layerManagerappend(backgroundSprite); } // Automatically start thread for game loop public void start() { isPlay = true; Thread t = new Thread(this); tstart(); } public void stop() { isPlay = false; } // Main Game Loop public void run() { Graphics g = getGraphics(); while (isPlay == true) { input(); drawScreen(g); try { Threadsleep(delay); } catch (InterruptedException ie) { } } } // Method to Handle User Inputs private void input() { int keyStates = getKeyStates(); playerSpritesetFrame(); if(isalive) { if(counter==) { enemyDirect=Mathabs(randomnextInt()%); } counter++; switch(enemyDirect) { case : enemyY=Mathmax(enemyY); break; case : enemyY=Mathmin(++enemyYheightenemySpritegetHeight()); break; case : enemyX=Mathmax(enemyX); break; case : enemyX=Mathmin(++enemyXwidthenemySpritegetWidth()); break; } counter=(counter++)%(sequencelength()); enemySpritesetFrame(sequence[counter]); } else { enemyY+=counter; enemyY=Mathmin(enemyYheightenemySpritegetHeight()); if(enemyYcounter++; enemySpritesetFrame(); } // Left if ((keyStates & LEFT_PRESSED) != ) { currentX = Mathmax( currentX ); playerSpritesetFrame(); } // Right if ((keyStates & RIGHT_PRESSED) != ) if (currentX + < width) { currentX = Mathmin(width currentX + ); playerSpritesetFrame(); } // Up if ((keyStates & UP_PRESSED) != ) { currentY = Mathmax( currentY ); playerSpritesetFrame(); } // Down if ((keyStates & DOWN_PRESSED) != ) { isdown=true; } if ((keyStates & DOWN_PRESSED) != ) { if(isdown) { if (currentY + < height) { currentY = Math.min(height, currentY + 1); playerSprite.setFrame(4); } } } if((keyStates & FIRE_PRESSED)!=0) { isalive=!isalive; counter=0; } if(!(enemyX+enemySprite.getWidth()|| enemyY+enemySprite.getHeight()|| enemyX>currentX+playerSprite.getWidth()|| enemyY>currentY+playerSprite.getHeight()) && isalive) { counter=0; isalive=false; } } // Method to Display Graphics private void |