Мне нужна помощь, я работаю над заданием, а геттеры и сеттеры не работают. так что я использую слушатель действия, когда нажата кнопка «Добавить сумму», она должна добавить сумму, которая была введена к сумме депозита, и делает это, но когда я вызываю getSavingBalance (); баланс все еще остается на нуле. не очень знакомый со стеком над потоком, не смог опубликовать весь мой код, потому что они говорят, что мне нужно добавить больше деталей, поэтому я просто оставил то, что наиболее важно.
JButton addBtn = new JButton("Add Amount");
addBtn.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
double deposit= Double.parseDouble(balance.getText());
setDeposit(deposit);
accBal.setText("Account Balance: "+getSavingBalance());
}
public class Bank {
int accountNumber;
static String accountType;
static double savingBalance;
static double deposit;
public Bank() {
this.accountNumber = 85061;
accountType = "Savings";
}
public static void setDeposit(double depos) {
deposit = deposit+depos;
}
public static void setSavingBalance(double saving) {
savingBalance = saving;
savingBalance+= deposit -withdraw;
}
public static void savingsFrame() {
JLabel accBal = new JLabel("Account Balance: "+ getSavingBalance());
JFrame savingsFrame = new JFrame("Bank Account");
savingsFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel savingsPanel= new JPanel(new GridLayout(2,2,1,1));
//savingsPanel.setBackground(Color.gray);
savingsPanel.setPreferredSize(new Dimension(550,100));
TitledBorder savingsTitle = new TitledBorder("Savings Account");
savingsTitle.setTitleJustification(TitledBorder.CENTER);
savingsPanel.setBorder(savingsTitle);
JLabel bal = new JLabel("Deposit Amount: ");
JTextField balance = new JTextField();
JLabel draw = new JLabel("Withdraw Amount: ");
JTextField withdraw = new JTextField();
JButton addBtn = new JButton("Add Amount");
addBtn.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
double deposit= Double.parseDouble(balance.getText());
setDeposit(deposit);
accBal.setText("Account Balance: "+getSavingBalance());
}
});
JButton withdrawBtn = new JButton("Withdraw Amount");
withdrawBtn.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
}
});
JButton updateBtn = new JButton("Update Account");
updateBtn.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent event) {
accBal.setText("Account Balanceee: "+ getSavingBalance());
}
});
}