title: How can I update my Balance whenever I deposit or withdraw?
body: <p>I would like my <strong>Balance updated</strong> whenever I deposit or withdraw. I'm still new to Java, GUI, ArrayList. I would like to create a simple bank program with just simple login showing options(withdraw, deposit, balance). Did I use a wrong code to get the Balance updated whenever I deposit or withdraw? I would like to have your help or tips. I'm sorry if it so long.
  // Account class</p>
  <pre><code>                            public class Account {
                              
                                  private double Withdraw;
                                  private double Deposit;
                                  private double Balance;
                                  
                                  public Account (double Withdraw, double Deposit, double Balance) {
                                      
                                      this.Withdraw = Withdraw;
                                      this.Deposit = Deposit;
                                      this.Balance = Balance;
                                  }
                                  
                                  public Account () {
                                      
                                  }
                                  
                                  public void Withdraw (double Sum) {
                                      this.Balance = this.Balance - Sum;
                                  }
                                  
                                  public void Deposit (double Sum) {
                                      this.Balance = this.Balance - Sum;
                                  }
                                  
                                  public void setBalance (double Blnc) {
                                      this.Balance = Blnc;
                                  }
                                  
                                  public double getBalance () {
                                      return this.Balance;
                                  }
                                  
                                  public double getWithdraw()
                                  {
                                      return this.Withdraw;
                                  }
                              
                                  public double getDeposit()
                                  {
                                      return this.Deposit;
                                  }
                              }
                      
                      // Balance  class
  
                          import javax.swing.JFrame;
                          import javax.swing.JLabel;
                          import javax.swing.JTextArea;
                          import javax.swing.JTextField;
                          
                          import java.awt.event.ActionEvent;
                          import java.awt.event.ActionListener;
                          import java.util.ArrayList;
                          import java.util.List;
                          
                          import javax.swing.JButton;
                          
                          public class Balance implements ActionListener {
                              
                              private List&lt;Account&gt; store;
                              
                              private static JLabel balance;
                              private static JTextField Balance;
                              
                              JFrame frame = new JFrame();
                              JButton OK = new JButton(&quot;OK&quot;);
                              // JButton Show = new JButton (&quot;SHOW&quot;);
                              // JTextArea text = new JTextArea();
                              
                              Balance() {
                                  
                                  store = new ArrayList&lt;Account&gt;();  
                                      
                                      frame.setSize(500, 300);
                                      frame.setTitle(&quot;BALANCE ACCOUNT&quot;); 
                                      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                      frame.setLayout(null);
                                      
                                      balance = new JLabel(&quot;YOUR BALANCE IS: &quot; + acnt.getBalance());
                                      balance.setBounds(200, 50, 200, 50);
                                      frame.add(balance);
                                      
                                  //  text = new JTextArea();
                                  //  text.setBounds(200,  80, 100, 50);
                                  //  frame.add(text);
                                      
                                  //  Show.addActionListener(this);
                                  //  Show.setBounds(250, 200, 100, 20);
                                  //  frame.add(Show);
                                      
                                      OK.addActionListener(this);
                                      OK.setBounds(380, 200, 100, 20);
                                      frame.add(OK);
                                                  
                                      frame.setVisible(true);             
                              }
                              
                              Account acnt = new Account();
                          
                              @Override
                              public void actionPerformed(ActionEvent e) {
                                  if (e.getSource()== OK) {
                                      acnt.setBalance(acnt.getBalance()+Integer.parseInt(balance.getText()));
                                      frame.setVisible(false);
                                       ATMOptionPanel atmoptionpanel = new ATMOptionPanel();
                                       // text.append(&quot;\nBalance=&quot;+acnt.getBalance());
                                  }
                                  
                                  }
                                      
                          }
  </code></pre>
  <pre><code>            // Deposit Class
  </code></pre>
  <pre><code>                import java.awt.event.ActionEvent;
                  import java.awt.event.ActionListener;
                  import java.util.ArrayList;
                  import java.util.List;
                  
                  import javax.swing.JButton;
                  import javax.swing.JFrame;
                  import javax.swing.JLabel;
                  import javax.swing.JOptionPane;
                  import javax.swing.JTextField;
                  // import java.util.Scanner;
                  
                  public class Deposit implements ActionListener{
                      
                      private List&lt;Account&gt; store;
                      
                      //Scanner scanner = new Scanner(System.in);
                      int Balance = 0, Deposit, Withdraw; 
                      
                      private static JLabel deposit;
                      private static JTextField depositText;
                      
                      JButton submit = new JButton(&quot;SUBMIT&quot;);
                      JButton back = new JButton(&quot;BACK&quot;);
                      
                      JFrame frame = new JFrame();
                      
                      Deposit () {
                              
                          store = new ArrayList&lt;Account&gt;();  
                          
                              frame.setSize(500, 300);
                              frame.setTitle(&quot;DEPOSIT MENU&quot;); 
                              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                              frame.setLayout(null);
                              
                              deposit = new JLabel(&quot;DEPOSIT: &quot;);
                              deposit.setBounds(150, 50, 100, 50);
                              frame.add(deposit);
                              
                              depositText = new JTextField(20);
                              depositText.setBounds(250, 65, 100, 20);
                              frame.add(depositText);
                              
                              submit.addActionListener(this);
                              submit.setBounds(230, 100, 100, 20);
                              frame.add(submit);
                              
                              back.addActionListener(this);
                              back.setBounds(340, 100, 100, 20);
                              frame.add(back);
                              
                              frame.setVisible(true);     
                      }
                  
                      Account acnt = new Account();
                  
                          @Override
                          public void actionPerformed(ActionEvent e) {
                              
                              // int Deposit = Integer.parseInt(depositText.getText());
                              
                              
                              if (e.getSource()== submit) {
                                  store.add(acnt);
                                  frame.setVisible(false);
                  
                                  Balance balance = new Balance();
                                  acnt.setBalance(acnt.getBalance());
                              }
                              
                              else if (e.getSource()== back) {
                                  frame.setVisible(false);
                                  store.add(acnt);
                                  ATMOptionPanel atmoptionpanel = new ATMOptionPanel(); 
                              }
                          }
                  }
  </code></pre>
  <p>// Withdraw class</p>
  <pre><code>            import java.awt.event.ActionEvent;
              import java.awt.event.ActionListener;
              import java.util.ArrayList;
              import java.util.List;
              
              import javax.swing.JButton;
              import javax.swing.JFrame;
              import javax.swing.JLabel;
              import javax.swing.JOptionPane;
              import javax.swing.JTextField;
              
              public class Withdraw implements ActionListener{
                  
                  private List&lt;Account&gt; store;
                  
                  int Balance = 0, Withdraw, Deposit;
                  
                  private static JLabel withdraw;
                  private static JTextField withdrawText;
                  
                  JButton back = new JButton(&quot;BACK&quot;);
                  JButton submit = new JButton(&quot;SUBMIT&quot;);
                  
                  JFrame frame = new JFrame();
                  
                      Withdraw() {
                          
                          store = new ArrayList&lt;Account&gt;();  
                          
                          frame.setSize(500, 300);
                          frame.setTitle(&quot;WITHDRAW MENU&quot;); 
                          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                          frame.setLayout(null);
                          
                          withdraw = new JLabel(&quot;WITHDRAW: &quot;);
                          withdraw.setBounds(150, 50, 100, 50);
                          frame.add(withdraw);
                          
                          withdrawText = new JTextField(20);
                          withdrawText.setBounds(250, 65, 100, 20);
                          frame.add(withdrawText);
                          
                          back.setBounds(320, 150, 100, 20);
                          frame.add(back);
                          
                          submit.addActionListener(this);
                          submit.setBounds(200, 150, 100, 20);
                          frame.add(submit);
                          
                          frame.setVisible(true);     
                  }
                      
                      Account acnt = new Account();
              
                      @Override
                      public void actionPerformed(ActionEvent e) {
                          // TODO Auto-generated method stub
                          if (e.getSource()== submit) {
                              if (Balance &lt;= Withdraw) {
                                  acnt.setBalance(acnt.getBalance()-Integer.parseInt(withdrawText.getText()));
                                  store.add(acnt);
                                  JOptionPane.showMessageDialog(null, &quot;Withdraw success!.&quot;, &quot;SUCCESS!&quot;, JOptionPane.INFORMATION_MESSAGE);
                              } else if (Balance &gt;= Withdraw)
                                  {
                                  JOptionPane.showMessageDialog(null, &quot;You don't have enough balance\nPlease deposit an amount first.&quot;, &quot;INSUFFICIENT BALANCE!&quot;, JOptionPane.ERROR_MESSAGE);
                                  }
                              
                              if (e.getSource()== back) {
                                  frame.setVisible(false);
                                  
                              }
                          }
                      }
              }
  </code></pre>
  <pre><code>    // OptionPanel
  </code></pre>
  <pre><code>        import java.awt.event.ActionEvent;
          import java.awt.event.ActionListener;
          import javax.swing.JButton;
          import javax.swing.JFrame;
          import javax.swing.JLabel;
          import javax.swing.JOptionPane;
          import javax.swing.JPanel;
          
          public class ATMOptionPanel implements ActionListener {
              
              private static JLabel BankOptions;
              
              JFrame frame = new JFrame();
              JButton withdraw = new JButton(&quot;WITHDRAW&quot;);
              JButton deposit = new JButton(&quot;DEPOSIT&quot;);
              JButton balance = new JButton(&quot;BALANCE&quot;);
              
              ATMOptionPanel() {
                  
                  frame.setSize(500, 300);
                  frame.setTitle(&quot;BANK ACCOUNT&quot;);
                  frame.setLayout(null);
                  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                  
                  BankOptions = new JLabel (&quot;MENU&quot;);
                  BankOptions.setBounds(230, 10, 200, 20);
                  frame.add(BankOptions);
                  
                  withdraw.addActionListener(this);
                  withdraw.setBounds(100, 80, 140, 25);
                  withdraw.setFocusable(false);
                  frame.add(withdraw);
                  
                  deposit.addActionListener(this);
                  deposit.setBounds(250, 80, 140, 25);
                  deposit.setFocusable(false);
                  frame.add(deposit);
                  
                  balance.addActionListener(this);
                  balance.setBounds(180, 120, 140, 25);
                  balance.setFocusable(false);
                  frame.add(balance);
                  
                  frame.setVisible(true);
              }
          
          @Override
          public void actionPerformed(ActionEvent e) {
              if (e.getSource()==withdraw) {
                  frame.setVisible(false);
                  Withdraw withdraw = new Withdraw();
              } 
              
              else if (e.getSource()==deposit) {
                  frame.setVisible(false);
                  Deposit deposit = new Deposit();
              }
              
              else if (e.getSource()==balance) {
                  frame.setVisible(false);
                  Balance balance = new Balance();
              }
          }
          
          }
  </code></pre>
  <pre><code>// Login
  </code></pre>
  <pre><code>    import java.awt.Color;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.JOptionPane;
      import javax.swing.JPanel;
      import javax.swing.JTextField;
      
      public class Login  implements ActionListener {
      
          private static JLabel welcome;
          private static JLabel userLabel;
          private static JTextField userText;
          private static JLabel passwordLabel;
          private static JTextField passwordText; 
          
          JFrame frame = new JFrame();
          JButton login = new JButton(&quot;Login&quot;); // create a Button with a text of &quot;Login&quot;
          
          Login() {
              frame.setSize(500, 300);
              frame.setTitle(&quot;BANK ACCOUNT&quot;); 
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.getContentPane().setBackground(Color.BLACK);
              frame.setLayout(null);
              
              welcome = new JLabel (&quot;WELCOME TO THE LOGIN PANEL&quot;,JLabel.CENTER);
              welcome.setBounds(150, 10, 220, 20);
              frame.add(welcome);
              
              userLabel =  new JLabel (&quot;USERNAME:\t&quot;); // Word &quot;User&quot; will appear.
              userLabel.setBounds(100, 50, 100, 50); // (x, y, width, height)
              frame.add(userLabel);
              
              userText = new JTextField(20); // rectangle box will appear at the left side of the word &quot;User&quot;.
              userText.setBounds(250, 65, 80, 20);
              frame.add(userText);
              
              passwordLabel = new JLabel (&quot;PASSWORD:\t&quot;); // Word &quot;Password&quot; will appear. 
              passwordLabel.setBounds(100, 90, 100, 50);
              frame.add(passwordLabel);
              
              passwordText = new JTextField(20); // rectangle box will appear at the left side of the word &quot;Password&quot;.
              passwordText.setBounds(250, 105, 80, 20);
              frame.add(passwordText);
      
              login.addActionListener(this);
              login.setBounds(200, 150, 100, 20);
              frame.add(login);
              
              frame.setVisible(true); 
              
              System.out.println(&quot;USERNAME:\tBank&quot;);
              System.out.println(&quot;PASSWORD:\tabcd123&quot;);
          }
          
          @Override
          public void actionPerformed(ActionEvent e) {
              
              String user = userText.getText();
              String password = passwordText.getText();
              
              if (user.equals(&quot;Bank&quot;) &amp;&amp; (password.equals(&quot;abcd123&quot;))) {
                  System.out.println(&quot;\nLogin Successfully!&quot;);
                  
                  frame.setVisible(false);
                  
                  ATMOptionPanel atmoptionpanel = new ATMOptionPanel();
              } 
              
              else    
              {
                  JOptionPane.showMessageDialog(null, &quot;PLEASE INPUT THE CORRECT USERNAME &amp; PASSWORD! \n Write what is on the console.&quot;, &quot;ERROR&quot;, JOptionPane.ERROR_MESSAGE);
              }
          }
      
      }
  </code></pre>
  <p>// ATMMain Class</p>
  <pre><code>public class ATMMain {
  
      public static void main(String[] args) {
          
          Login login = new Login();
  
      }
  
  }
  </code></pre>