java - GUI 卡住了。(Java netbeans),
问题描述
我在我的 GUI 中添加了一个函数,它永远存在。它以前工作正常。
public void setBalance(String username,double balance){
Node current = headNode;
while(current!=null)
{
if(current.username.equalsIgnoreCase(username))
{
current.setBalance(balance);
}else{
current=current.getNext();
}
}
}
这是我写的函数,它只是卡在那里。
private void D_EnterActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String username = accountUsername.getText();
String password = accountPassword.getText();
boolean flag = false;
S_Balance=l.findBalance(username, password);
Deposit_text.setVisible(true);
num1 = S_Balance + Double.parseDouble(D_deposit_text.getText()) ;
Deposit_text.setEditable(false);
Deposit_text.setText("Previous Balance:"+Double.toString(S_Balance)+"\nNew Balance:"+Double.toString(num1));
S_Balance = S_Balance + Double.parseDouble(D_deposit_text.getText());
l.setBalance(username, S_Balance);
this.N_Deposit++;
D_deposit_text.setText("");
if(S_Balance < 25)
{
Status.setVisible(true);
Active_Status.setVisible(false);
S_TextField.setText("Your Balance is less than $25");
SmileyFace.setVisible(false);
Smiley1.setVisible(true);
}else{
Status.setVisible(false);
Active_Status.setVisible(true);
S_WithDraw.setEnabled(true);
S_TextField.setText("You are good to go!!!");
SmileyFace.setVisible(true);
Smiley1.setVisible(false);
W_Enter.setEnabled(true);
}
}
这就是它的名称。
解决方案
你被卡住了,因为当你找到用户名时,你并没有打破 while 循环(所以它会永远运行)。您应该执行以下操作:
public void setBalance(String username,double balance){
Node current = headNode;
while(current!=null)
{
if(current.username.equalsIgnoreCase(username))
{
current.setBalance(balance);
break; // this will break the loop
}else{
current=current.getNext();
}
}
}
推荐阅读
- sql - 将一列迁移到多列
- kubernetes - 启用网络策略的 Kubernetes 运行状况检查失败
- ruby-on-rails - 更新 rails ActiveModel 条目时的 Psych::DisallowedClass
- android - 一个屏幕上的两个片段。两个片段的滚动动画
- php - 如何避免页面刷新后重新提交
- php - PHP/MySQL 的字符编码问题
- python - 使用 2 个列表的 Python 循环
- c# - 用作资产时没有出现在 WPF 中的视频和音乐
- reactjs - 遵循规则的 react-hooks/exhaustive-deps 会导致错误。不是所有的依赖都应该被关注吗?
- javascript - 尝试使用 JWT 创建登录时出现“不是函数”错误