I wasn't too sure what to title this question, apologies in advance. I currently have a value of say 50 stored in the BidderArray. I want to be able to increase that 50 by any given number entered into a text field.
So say I want to add 10 to the existing 50, it will return 60. Currently when I add the 10 the 50 is replaced by 10 instead of adding the two together. I understand why my code is doing this but haven't been able to find any tutorials or hints on what I should be doing instead.
Here is the code:
package abc;
import java.awt.*;
public class Funds extends javax.swing.JFrame {
int i = 0;
Bidder bidbal = new Bidder();
/** Creates new form Funds */
public Funds() {
initComponents();
}
private void addActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int f = 0;
boolean validEntries = true;
try{
f = Integer.parseInt(amount.getText());
Bidder.BidderArray.get(i).setRegFee(f);
} catch (Exception error) {
validEntries = false;
amount.setBackground(Color.red);
}
if (validEntries) {
Bidder.exportBidder();
Home home = new Home();
home.setVisible(true);
this.dispose();
}
}
}
Bidderis, but one possible reasoning for your problem is that when you add the 10 elements to your ArrayList, you are actually changing the reference to a new ArrayList, and then adding the 10 elements to that new List.