为什么这个int不会递增? [英] Why isn't this int incrementing?
本文介绍了为什么这个int不会递增?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我被困在一个简单的问题上,但我真的找不到它为什么不起作用。每次调用该方法时,我都会尝试增加 mijnScore
1。但不知何故, mijnScore
在方法完成后回到0。
I am stuck on probably an easy problem, but I really can't find why it isn't working. I am trying to increase mijnScore
with 1 each time the method gets called. But somehow mijnScore
goes back to 0 after the method is done.
int mijnScore = 0;
...
public void updateUI() {
System.out.println("updateUI");
SwingUtilities.invokeLater(new Runnable() {
public void run() {
ikWin = true;
while(ikWin) {
mijnScore++;
System.out.println("mijnScore" + mijnScore);
Scoresp1.setText(mijnScore + "");
ikWin = false;
positie = 0;
}
}
});
}
已解决
使变量静态解决了我的问题。
Making the variable static solved my problem.
static int mijnScore = 0;
推荐答案
我不知道你用不同的对象打电话或者相同。只是猜测使变量mijnScore静态然后它可能没问题。
I dont know wheather you are calling with different objects or same.Just as a guess Make the variable mijnScore static then it may be ok.
这篇关于为什么这个int不会递增?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文