使用Jbulider开发j2me程序(转)

首先开启Jbuilder.建立一个Project。
2005112152514558.jpg

然后填写名字和路径。继续:

2005112152525734.jpg

然后选择JDK路径,本身已有WTK2.1,你可以选择。但是你也可以自己选择其他的WTK版本。
2005112152535215.jpg

点击jdk后面的路径按钮,继续:

2005112152547124.jpg

然后ok,next.工程建立完毕.

接着点击file->New:

2005112152557237.jpg

然后在对话框左边选择Micro,你就能看到右边出现MIDlet,Displayable.

接上面的:如图示

200511215266783.jpg

点击MIDlet or Displayable,则让你输入MIDlet的名字.如图:

2005112152616214.jpg

继续下一步,让你输入一个Displayable的名字,包括类型(form,canvas等),是否自动加载Command

等等

2005112152626944.jpg

然后Jbuilder自动生成所需代码,以及Jbuilder自加的一些东西.你可以添加或修改之.

这里我将本站一篇关于介绍Gamecanvas的文章的代码拿过来,做少量修改,作为本文章的一个演示;

TestMIDlet.java文件:

package temps;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
*

Title:


*
*

Description:


*
*

Copyright: Copyright (c) 2005


*
*

Company:


*
* @author not attributable
* @version 1.0
*/
public class TestMIDlet extends MIDlet
{
private Display display;

public void startApp()
{
try
{
display = Display.getDisplay(this);
Displayable1 gameCanvas = new Displayable1();
gameCanvas.start();
display.setCurrent(gameCanvas);
}
catch (Exception ex)
{
System.out.println(ex);
}
}

public Display getDisplay()
{
return display;
}

public void pauseApp()
{
}

public void destroyApp(boolean unconditional)
{
exit();
}

public void exit()
{
System.gc();
destroyApp(false);
notifyDestroyed();
}
}

Displayable1.java内容:

package temps;

import javax.microedition.lcdui.*;
import java.util.Random;
import javax.microedition.lcdui.game.*;
/**
*

Title:


*
*

Description:


*
*

Copyright: Copyright (c) 2005


*
*

Company:


*
* @author not attributable
* @version 1.0
*/
public class Displayable1 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(System.currentTimeMillis());
private final int[] sequence={0,1,2,1,0,1,2,1,0,1,2,1,1,1,1,1,1};
private int counter=0;
private int enemyX,enemyY;
private int enemyDirect=0;
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 Displayable1() throws Exception
{
super(true);
width = getWidth();
height = getHeight();

currentX = width / 2;
currentY = height / 2;
enemyX=width/4;
enemyY=height/4;
delay = 100;

Image playerImage=null;
Image backgroundImage=null;
Image enemy=null;
// Load Images to Sprites
try
{
playerImage = Image.createImage("/transparent.png");
backgroundImage = Image.createImage("/background.png");
enemy=Image.createImage("/frames.png");
}
catch(Exception e)
{
System.out.println("get Image error!"+e.getMessage());
}

playerSprite = new Sprite(playerImage, 32, 32);
System.out.println(playerSprite.getRawFrameCount());
enemySprite=new Sprite(enemy,50,21);
backgroundSprite = new Sprite(backgroundImage);
layerManager = new LayerManager();
layerManager.append(playerSprite);
layerManager.append(enemySprite);
layerManager.append(backgroundSprite);

}

// Automatically start thread for game loop
public void start()
{
isPlay = true;
Thread t = new Thread(this);
t.start();
}

public void stop()
{
isPlay = false;
}

// Main Game Loop
public void run()
{
Graphics g = getGraphics();
while (isPlay == true)
{
input();
drawScreen(g);
try
{
Thread.sleep(delay);
}
catch (InterruptedException ie)
{

}
}
}


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-127125/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10294527/viewspace-127125/

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:编程工作室 设计师:CSDN官方博客 返回首页
评论
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值