import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;

public class ATM extends Applet implements ActionListener {

   // the three buttons on the left of the output window
   JButton leftButtonA, leftButtonB, leftButtonC, leftButtonD;

   // the output window (a text area)
   JTextArea outputWindow;

   // the buttons on the numeric pad
   JButton num1, num2, num3, num4, num5, num6, num7, num8, num9, num0, num00, numDot;

   // enter and cancel buttons
   JButton enter, cancel;


   public void init() {

      // first, we build the top row
      JPanel topRow = new JPanel(new FlowLayout());
      topRow.add(new JLabel("ATM by CitiZach"));

      // next, we build the left-side row of buttons
      JPanel leftSide = new JPanel();
      leftSide.setLayout(new BoxLayout(leftSide, BoxLayout.Y_AXIS));
      leftButtonA = new JButton("A");
      leftButtonB = new JButton("B");
      leftButtonC = new JButton("C");
      leftButtonD = new JButton("D");
      leftSide.add(new JLabel(" ")); 
      leftSide.add(leftButtonA);
      leftSide.add(new JLabel(" ")); 
      leftSide.add(new JLabel(" ")); 
      leftSide.add(new JLabel(" ")); 
      leftSide.add(leftButtonB);
      leftSide.add(new JLabel(" ")); 
      leftSide.add(new JLabel(" ")); 
      leftSide.add(new JLabel(" ")); 
      leftSide.add(leftButtonC);
      leftSide.add(new JLabel(" ")); 
      leftSide.add(new JLabel(" ")); 
      leftSide.add(new JLabel(" ")); 
      leftSide.add(leftButtonD);

      // build the center pane, an output window
      JPanel center = new JPanel();
      outputWindow = new JTextArea(20, 20);
      center.add(new JScrollPane(outputWindow));

      // build the right pane
      JPanel numberPad = new JPanel(new GridLayout(4,3));
      num1 = new JButton("1");
      num2 = new JButton("2");
      num3 = new JButton("3");
      num4 = new JButton("4");
      num5 = new JButton("5");
      num6 = new JButton("6");
      num7 = new JButton("7");
      num8 = new JButton("8");
      num9 = new JButton("9");
      num0 = new JButton("0");
      num00 = new JButton("00");
      numDot = new JButton(".");
      numberPad.add(num1);
      numberPad.add(num2);
      numberPad.add(num3);
      numberPad.add(num4);
      numberPad.add(num5);
      numberPad.add(num6);
      numberPad.add(num7);
      numberPad.add(num8);
      numberPad.add(num9);
      numberPad.add(num0);
      numberPad.add(numDot);
      numberPad.add(num00);
      JPanel enterCancel = new JPanel();
      enter = new JButton("ENTER");
      cancel = new JButton("CANCEL");
      enterCancel.add(enter);
      enterCancel.add(cancel);
      JPanel rightSide = new JPanel();
      rightSide.setLayout(new BoxLayout(rightSide, BoxLayout.Y_AXIS));
      rightSide.add(numberPad);
      rightSide.add(enterCancel);


      // now, put everything together... the top row, left and right side, and the center
      setLayout(new BorderLayout());
      add(BorderLayout.PAGE_START, topRow);
      add(BorderLayout.LINE_START, leftSide);
      add(BorderLayout.CENTER, center);
      add(BorderLayout.LINE_END, rightSide);


      // finally, in order to determine when the user presses a button, we must listen
      // events on ALL ov the buttons created...
      leftButtonA.addActionListener(this);
      leftButtonB.addActionListener(this);
      leftButtonC.addActionListener(this);
      leftButtonD.addActionListener(this);

      num1.addActionListener(this);
      num2.addActionListener(this);
      num3.addActionListener(this);
      num4.addActionListener(this);
      num5.addActionListener(this);
      num6.addActionListener(this);
      num7.addActionListener(this);
      num8.addActionListener(this);
      num9.addActionListener(this);
      num0.addActionListener(this);
      num00.addActionListener(this);
      numDot.addActionListener(this);

      enter.addActionListener(this);
      cancel.addActionListener(this);
   }

   // How to handle various events
   public void actionPerformed(ActionEvent e) {

      // This is how you can determine which button was pressed...

      if (e.getSource() == leftButtonA) {

         outputWindow.setText("You pressed button A");

      } else if (e.getSource() == leftButtonB) {

         outputWindow.setText("You pressed button B");

      } else if (e.getSource() == leftButtonC) {

         outputWindow.setText("You pressed button C");

      } else if (e.getSource() == leftButtonD) {

         outputWindow.setText("You pressed button D");

      } else if (e.getSource() == num1) {

         outputWindow.setText("You pressed button 1");

      } else if (e.getSource() == num2) {

         outputWindow.setText("You pressed button 2");

      } else if (e.getSource() == num3) {

         outputWindow.setText("You pressed button 3");

      } else if (e.getSource() == num4) {

         outputWindow.setText("You pressed button 4");

      } else if (e.getSource() == num5) {

         outputWindow.setText("You pressed button 5");

      } else if (e.getSource() == num6) {

         outputWindow.setText("You pressed button 6");

      } else if (e.getSource() == num7) {

         outputWindow.setText("You pressed button 7");

      } else if (e.getSource() == num8) {

         outputWindow.setText("You pressed button 8");

      } else if (e.getSource() == num9) {

         outputWindow.setText("You pressed button 9");

      } else if (e.getSource() == num0) {

         outputWindow.setText("You pressed button 0");

      } else if (e.getSource() == num00) {

         outputWindow.setText("You pressed button 00");

      } else if (e.getSource() == numDot) {

         outputWindow.setText("You pressed button .");

      } else if (e.getSource() == enter) {

         outputWindow.setText("You pressed button ENTER");

      } else if (e.getSource() == cancel) {

         outputWindow.setText("You pressed button CANCEL");

      }

   }

}
