Results 1 to 2 of 2
  1. #1
    thelinuxguy is offline Member
    Join Date
    Dec 2008
    Posts
    44
    Rep Power
    0

    Default Menu driven system - atm

    Hi

    I am trying to build a menu driven java program to simulate an atm. I have already got it working, at least the back end, I have then come to build the GUI and have found myself stumped. Here is my code:-

    import java.sql.*;
    import java.io.*;
    import java.util.Scanner;
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;

    class ATM extends JFrame implements ActionListener, TextListener
    {
    String cc;
    String acc = "1";
    String cv = "1";
    String sort = "1";
    String card = "1";

    Account a = new Account();
    String pin;
    String customerPin; //to take in pin from keypad
    boolean allow;
    char selection;
    int amountToWithdraw;
    int amount;
    String me;
    MainMenu menu = new MainMenu(a);

    JPanel panel1 = new JPanel();
    JPasswordField pw = new JPasswordField(4);
    JPanel panel2 = new JPanel();
    JPanel panel3 = new JPanel();
    JPanel panel4 = new JPanel();
    JPanel panel5 = new JPanel();
    JLabel jabel = new JLabel("ATM");
    JTextArea displayArea = new JTextArea(30, 40);
    //ten digit key pad
    JButton enter = new JButton("Enter");
    JButton cancel = new JButton("Cancel");
    JButton one = new JButton("1");
    JButton two = new JButton("2");
    JButton three = new JButton("3");
    JButton four = new JButton("4");
    JButton five = new JButton("5");
    JButton six = new JButton("6");
    JButton seven = new JButton("7");
    JButton eight = new JButton("8");
    JButton nine = new JButton("9");
    JButton zero = new JButton("0");

    public ATM()
    {
    super("ATM");

    Account a = new Account();
    String pin;
    String customerPin; //to take in pin from keypad
    boolean allow;
    char selection;
    int amountToWithdraw;
    int amount;


    a.getPin(acc, sort, card, cv);
    pin = a.getPin(acc,sort,card,cv);
    //System.out.println(pin);
    int f = a.funds();
    //MainMenu menu = new MainMenu(a);


    setSize(500, 500);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new BorderLayout());
    panel1.add(jabel);
    panel1.add(pw);
    pw.setEchoChar('*');
    panel5.add(displayArea);
    //selection = myScanner.findInLine(".").charAt(0);
    //menu.enterSelection(selection, a);
    panel2.setSize(40, 40);
    panel3.setSize(40, 40);
    panel4.setSize(40, 40);
    add(panel1, BorderLayout.NORTH);
    add(panel2, BorderLayout.SOUTH);
    add(panel3, BorderLayout.EAST);
    add(panel4, BorderLayout.WEST);
    add(panel5, BorderLayout.CENTER);
    GridLayout family = new GridLayout(3, 3, 10 ,10);
    panel2.setLayout(family);
    panel2.add(one);
    panel2.add(two);
    panel2.add(three);
    panel2.add(four);
    panel2.add(five);
    panel2.add(six);
    panel2.add(seven);
    panel2.add(eight);
    panel2.add(nine);
    panel2.add(zero);
    panel2.add(enter);
    panel2.add(cancel);
    two.setFocusable(true);
    enter.addActionListener(this);
    cancel.addActionListener(this);
    one.addActionListener(this);
    two.addActionListener(this);
    three.addActionListener(this);
    four.addActionListener(this);
    five.addActionListener(this);
    six.addActionListener(this);
    seven.addActionListener(this);
    eight.addActionListener(this);
    nine.addActionListener(this);
    zero.addActionListener(this);
    pw.addActionListener(this);
    setVisible(true);



    //displayArea.setText(me);
    // selection = myScanner.findInLine(".").charAt(0);
    // menu.enterSelection(selection, a);
    }




    public void actionPerformed(ActionEvent e)
    {
    Object source = e.getSource();

    if(source == pw)
    {
    a.getPin(acc, sort, card, cv);
    String customerPin = pw.getText();
    allow = a.checkPin(customerPin);




    if(allow != true)
    {
    System.exit(0);
    }
    else
    {

    String me = menu.getSelection();
    displayArea.setText(me);

    }
    }

    if(source == one)
    {

    int m = a.checkBalance();
    int f = a.funds();
    displayArea.setText("\nAccount Balance" + m);
    displayArea.append("\nAvailable Funds" + f);
    }

    if(source == two)
    {

    CashWithReceipt cash = new CashWithReceipt(a);
    String cl = cash.withdrawelOptions();
    displayArea.setText(cl);



    if(source == one)
    {
    char choice = '1';
    cash.howMuchToWithdraw(choice, a);
    }
    }

    if(source == three)
    {
    selection = '3';
    menu.enterSelection(selection, a);
    }
    if(source == four)
    {
    selection = '4';
    menu.enterSelection(selection, a);
    }
    if(source == five)
    {
    selection = '5';
    menu.enterSelection(selection, a);
    }
    if(source == six)
    {
    selection = '6';
    menu.enterSelection(selection, a);
    }
    if(source == seven)
    {
    selection = '7';
    menu.enterSelection(selection, a);
    }
    if(source == eight)
    {
    selection = '8';
    System.exit(0);
    menu.enterSelection(selection, a);
    }
    if(source == cancel)
    {
    System.exit(0);
    }
    }






    public void textValueChanged(TextEvent txt)
    {
    }

    }

    What I would like to know is whether it is possible to have a sub feature to a JButton. For example if button one is pressed, would it be possible to open up a list of new options whereby if one is pressed again, then a selection from a second menu is selected.

    Hope this makes sense.

    Sincerely

    TheLinuxGuy

  2. #2
    thelinuxguy is offline Member
    Join Date
    Dec 2008
    Posts
    44
    Rep Power
    0

    Default Problem Solved

    I have figured out a way to solve my problem.

    Thanks to anyone who was thinking about helping.

    Kind Regards

    TheLinuxGuy

Similar Threads

  1. Replies: 0
    Last Post: 07-25-2008, 02:32 PM
  2. Replies: 1
    Last Post: 07-13-2008, 03:16 PM
  3. Replies: 0
    Last Post: 07-07-2008, 04:47 PM
  4. React to menu action and checkbox menu
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-27-2008, 07:50 PM
  5. Replies: 7
    Last Post: 05-09-2008, 07:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •