【发布时间】:2015-09-28 07:34:06
【问题描述】:
我正在创建一个应用程序,当我单击按钮以将文本字段中的值增加 1 时,它会崩溃。这是一个按钮单击事件。
我已将所有内容放在一个永远不会结束的 while 循环中。然后 ifs 将 int 中的值增加 1,然后将其存储到一个字符串中,该字符串将值设置为文本框。我还将包括一个减少按钮来执行相反的操作。
String SetUp = findTxtComp().getText();
int ChstSetLoop;
ChstSetLoop = 1;
while(ChstSetLoop == 1){
ChstSetLoop = 1;
if(SetUp.equals("0")){
SetUp = "1";
findTxtComp().setText("1");
ChstSetLoop = 0;
}
else if(SetUp.equals("1")){
SetUp = "2";
findTxtComp().setText(SetUp);
ChstSetLoop = 0;
}
else if(SetUp.equals("2")){
SetUp = "3";
findTxtComp().setText(SetUp);
ChstSetLoop = 0;
}
else if(SetUp.equals("3")){
SetUp = "4";
findTxtComp().setText(SetUp);
ChstSetLoop = 0;
}
else if(SetUp.equals("4")){
SetUp = "5";
findTxtComp().setText(SetUp);
ChstSetLoop = 0;
}
else{
SetUp = "0";
}
}
}
}
【问题讨论】:
-
也许想要包含错误?
findTxtComp()是做什么的? -
你永远不会改变
ChstSetLoop的值,所以你的循环当然永远不会结束。其余的大部分代码都是毫无意义的。foo = 4; foo = String.valueOf(foo)?为什么只是foo = "4"? -
findTxtComp() 将找到名为 txtcomp 的文本框。我正在使用代号一。该按钮应该在每次按下时将文本框中的数字增加 1。有两个变量 SetUP 是整数,SetUp 是字符串。
-
我想通了。看代码谢谢:)
标签: if-statement button netbeans codenameone