So I am creating a program which has a standard bank account balance of 500. The program asks the user if they would like to Withdraw or Deposit money, then calculate how much they Withdrew or Deposited and update the current balance. Why is it not working and how would I fix it?
public class MyFrame extends JFrame {
private JPanel panel;
private JLabel wordsLabel;
private JLabel balanceLabel;
private JLabel choiceLabel;
private JTextField transactionAmount;
private JButton depositButton;
private JButton withdrawButton;
private double balance;
public MyFrame() {
final int FIELD_WIDTH = 10;
balance = 500;
panel = new JPanel();
wordsLabel = new JLabel();
balanceLabel = new JLabel();
choiceLabel = new JLabel();
transactionAmount = new JTextField(FIELD_WIDTH);
JPanel buttonPanel = new JPanel();
ButtonGroup myGroup = new ButtonGroup();
//panel.setLayout(new BorderLayout());
depositButton = new JButton("Deposit");
withdrawButton = new JButton("Withdraw");
transactionAmount.setText("0");
wordsLabel.setText("Welcome to Wes Banco! Your current balance is: ");
balanceLabel.setText("500");
choiceLabel.setText("How much would you like to deposit/withdraw?");
panel.add(wordsLabel);
panel.add(balanceLabel);
panel.add(choiceLabel);
panel.add(transactionAmount);
myGroup.add(depositButton);
myGroup.add(withdrawButton);
buttonPanel.add(depositButton);
buttonPanel.add(withdrawButton);
panel.add(depositButton);
ButtonListener myListener = new ButtonListener();
depositButton.addActionListener(myListener);
withdrawButton.addActionListener(myListener);
panel.add(buttonPanel);
this.add(panel);
}
class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
double amount = Double.parseDouble(transactionAmount.getText());
if (amount == 0) {
JOptionPane.showMessageDialog(null, "Enter an amount");
}
if (depositButton.isSelected()) {
balanceLabel.setText("" + 500 + amount);
JOptionPane.showMessageDialog(null,
"You have deposited: " + amount);
}
if (withdrawButton.isSelected()) {
}
}
}
}