请问Java中debug和run的结果不同该怎么解决

洛酒 2017-12-21 11:10:01
Java实践的作业我写的是一个联机的飞行棋,然后现在投掷到6时点击飞机应该起飞,debug时一切正常飞机确实起飞了,但是run时就没有反应,请问下是为什么

部分代码:

// 投掷骰子
JButton PlayButton = new JButton(Pplay);
PlayButton.setBounds(855, 180, 150, 50);
PlayButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
int rand = (int) (Math.random() * 6);
diceLable.setIcon(RandomDice[rand]);
gameControl.setStep(rand);
gameControl.setTypePlane(TypePlane);
gameControl.setLine(gameData.getLine(GameDispose.COLORARRAY[TypePlane % 4]));
TypePlane++;
PlayButton.setVisible(false);

Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
diceLable.setIcon(resultDice[rand]);
PlayButton.setVisible(true);

PlaneMove();
}
}, 2000);

}
});

// 飞机移动
public void PlaneMove() {
int TypeOfPlane = gameControl.getTypePlane();
int StepOfPlane = gameControl.getStep();

Plane[] ChoosePlane = new Plane[4];
for (int i = 0; i < 4; i++)
ChoosePlane[i] = planes[TypeOfPlane][i];

// 添加鼠标监听
for (Plane p1 : ChoosePlane)
p1.addMouseListener();
while (true) {
// 当玩家选择了要移动的飞机时
//int current = gameData.getNumberOfCurrentPlane();
if (gameData.getNumberOfCurrentPlane() != -1) {
// 移动选中的飞机
gameControl.movePlane(gameData.getNumberOfCurrentPlane(), StepOfPlane, ChoosePlane[gameData.getNumberOfCurrentPlane()]);
// 重置当前选中飞机编号为-1
gameData.setNumberOfCurrentPlane(-1);
// 移除鼠标监听
for (Plane p2 : ChoosePlane)
p2.removeMouseListener();
break;
}
}
}

// 移动飞机
public void movePlane(int index, int stepOfPlanes, Plane plane) {
// 飞机在停机坪
if (plane.getLoc() == -2) {
//if (stepOfPlanes == 6)
FrameGame.PlaneStart(this.typePlane, index);
}

// 飞机起飞位置
public static void PlaneStart(int type, int index) {
if (type == 0)
planes[0][index].setLocation(156, 704);
else if (type == 1)
planes[1][index].setLocation(16, 159);
else if (type == 2)
planes[2][index].setLocation(561, 17);
else if (type == 3)
planes[3][index].setLocation(702, 562);

planes[type][index].setLoc(-1);
}
...全文
746 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
mmqw 2017-12-21
  • 打赏
  • 举报
回复
在起飞的位置加一个输出,看下debug和run是否都有输出
洛酒 2017-12-21
  • 打赏
  • 举报
回复
问题解决了,谢谢大家 我在添加鼠标监听下面sleep了一秒,然后问题就解决了
oyljerry 2017-12-21
  • 打赏
  • 举报
回复
debug是有断点等,是不是有暂停,直接运行就不会有等待。做好同步
usecf 2017-12-21
  • 打赏
  • 举报
回复
加个打印log看看debug和run下执行是不是一致 或者在run下加个几秒延迟试试

58,452

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧