/* This is the main atm program The user does all the transaction in here Start money is 1000.00 * */ import javax.swing.*; import java.awt.*; import java.awt.event.*; public class MainAtm extends JFrame { JPanel panel; static double amount = 1000.00; JButton dep; JButton wi; JButton cb; JButton x; public MainAtm() { // Sets the title of the atm setTitle("Welcome to the ATM"); // Sets the size of the atm setSize(300, 200); // Sets the action when the window is close setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Sets the location of the window to the middle of the screen setLocationRelativeTo(null); // Create 4 buttons dep = new JButton("Deposit"); wi = new JButton("WithDraw"); cb = new JButton("Check Balance"); x = new JButton("Exit"); // Create a panel and add the buttons to the panel panel = new JPanel(); panel.add(dep); panel.add(wi); panel.add(cb); panel.add(x); // Add the panel to the content pane add(panel); // Create event listener for the buttons dep.addActionListener(new ButtonListener()); wi.addActionListener(new ButtonListener()); cb.addActionListener(new ButtonListener()); x.addActionListener(new ButtonListener()); // Sets the visibility of the window setVisible(true); } // Add the deposit money to the amount public static void setDeposit(double newamount) { amount += newamount; } // Subtract the withdraw money from the amount public static void setWithDraw(double newamount) { amount -= newamount; } // Returns the amount of the money public static double getAmount() { return amount; } public class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { // Checks for the balance if(e.getSource() == cb) { JOptionPane.showMessageDialog(null, "Your current balance is " + getAmount()); } // Ask the user how much they want to deposit if(e.getSource() == dep) { String getamount = JOptionPane.showInputDialog("How much do you want to deposit"); double depamount = Double.parseDouble(getamount); setDeposit(depamount); } // Ask the user how much they want to withdraw if(e.getSource() == wi) { String takeamount = JOptionPane.showInputDialog("How much do you want to withdraw"); double wiamount = Double.parseDouble(takeamount); setWithDraw(wiamount); } // Exit the program if(e.getSource() == x) { JOptionPane.showMessageDialog(null, "Thank you for using the program"); System.exit(0); } } } }