I added a function in my GUI and it holds for forever. It was working fine before.
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(); } } }
This is the function I wrote, and it just stuck there.
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); } }
This is where it is called.
Advertisement
Answer
You got stuck because when you are finding the username, you are not breaking the while loop (so it would run forever). You should do something like:
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(); } } }