大家调试j2me游戏时一般都调试那块?
import
java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class CircleMenuCanvas extends Canvas implements Runnable{
double pi = Math.PI;
public final int MENURIGHT = 1;
public final int MENULEFT = 0;
Image menuImage[] = new Image[6];
int []jiaodu = {330,30,90,150,210,270};//静态初始化,我写的
String menuName[] = {"新游戏","继续游戏","游戏设置","高分榜","游戏帮助","退出游戏"};
int x = getWidth()/2;
int y = getHeight()/2;
int count = 0;
int local;
int index = 0;
Font f;
boolean running = false;
/**
* 构造方法
*
*/
public CircleMenuCanvas() {
super();
for(int i=0;i<6;i++)
{
int s = i+1;
try {
menuImage[i] = Image.createImage("/res/"+s+".png");
} catch (
IOException e1) {
e1.printStackTrace();
}
}
f = Font.getDefaultFont();
}
/**
* @param g 画笔
*/
protected void paint(Graphics g) {
g.setColor(0xffffff);
g.fillRect(0,0,getWidth(),getHeight());
g.drawLine(x,y,x,y);
g.drawImage(menuImage[0],(int)(x+50*Math.cos(Math.toRadians(jiaodu[0]))),(int)(y-50*Math.sin(Math.toRadians(jiaodu[0]))),Graphics.HCENTER |Graphics.VCENTER);
g.drawImage(menuImage[1],(int)(x+50*Math.cos(Math.toRadians(jiaodu[1]))),(int)(y-50*Math.sin(Math.toRadians(jiaodu[1]))),Graphics.HCENTER |Graphics.VCENTER);
g.drawImage(menuImage[2],(int)(x+50*Math.cos(Math.toRadians(jiaodu[2]))),(int)(y-50*Math.sin(Math.toRadians(jiaodu[2]))),Graphics.HCENTER |Graphics.VCENTER);
g.drawImage(menuImage[3],(int)(x+50*Math.cos(Math.toRadians(jiaodu[3]))),(int)(y-50*Math.sin(Math.toRadians(jiaodu[3]))),Graphics.HCENTER |Graphics.VCENTER);
g.drawImage(menuImage[4],(int)(x+50*Math.cos(Math.toRadians(jiaodu[4]))),(int)(y-50*Math.sin(Math.toRadians(jiaodu[4]))),Graphics.HCENTER |Graphics.VCENTER);
g.drawImage(menuImage[5],(int)(x+50*Math.cos(Math.toRadians(jiaodu[5]))),(int)(y-50*Math.sin(Math.toRadians(jiaodu[5]))),Graphics.HCENTER |Graphics.VCENTER);
g.setColor(0);
g.drawString(menuName[index],x- f.stringWidth(menuName[index])/2,y-5,0);
}
public void keyPressed(int keycode)
{
int key = getGameAction(keycode);
if((key == Canvas.DOWN || key == Canvas.RIGHT) && running == false)
{
local = MENURIGHT;
Thread t = new Thread(this);
t.start();
}
if((key == Canvas.UP || key == Canvas.LEFT) && running == false)
{
local = MENULEFT;
Thread t = new Thread(this);
t.start();
}
if(key == Canvas.FIRE)
{
//写下你按确定键的代码就好了
}
}
public void run()
{
running = true;
if(local == MENULEFT)
{
index--;
if(index < 0 )
index = 5;
}
if(local == MENURIGHT){
index++;
if(index>5)
index =0;
}
while(count<60)
{
for(int i=0;i<jiaodu.length;i++)
{
if(local == MENULEFT)
jiaodu[i]++;
else
jiaodu[i]--;
}
repaint();
count++;
int sleep;
sleep = Math.abs(30 - count);
try {
Thread.sleep(sleep);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
count=0;
running = false;
}
}
比如这个程序,我想测试下public void keyPressed(int keycode){}里面这些代码运行的步骤还有public void run(){}
里面的代码,但是Debug这些代码断不住,很是苦恼,大家是怎么办的,有什么好办法吗?
------解决方案--------------------
可以断住, 你把debug的 time设置一下