所以我正在编写一个相当低级别的Java编程程序。这就是我遇到的问题:
//The String fillText is given a value earlier in the program
if ("".equals(txa1.getText()))
{
txa1.setText(fillText);
txa1.setVisible(true);
}
else if ("".equals(txa2.getText()))
{
txa2.setText(fillText);
txa2.setVisible(true);
}
else if ("".equals(txa3.getText()))
{
txa3.setText(fillText);
txa3.setVisible(true);
}
else if ("".equals(txa4.getText()))
{
txa4.setText(fillText);
txa4.setVisible(true);
}
else if ("".equals(txa5.getText()))
{
txa5.setText(fillText);
txa5.setVisible(true);
}
...
此代码似乎总是用 fillText 填充所有文本区域(txaX)。我希望它只执行第一个返回 true 的语句,然后跳出 if-else-statement。
我尝试使用 switch-case 来完成它,但最终失败了,因为在程序运行期间更改了字符串。
怎么了?
提前致谢!