Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7646689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:16:21+00:00 2026-05-31T10:16:21+00:00

public class ATMgui extends JFrame implements ActionListener { /** * */ private static final

  • 0
public class ATMgui extends JFrame implements ActionListener {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    public static final int WIDTH = 500;
    public static final int HEIGHT = 200;
    private ATMbizlogic theBLU;// short for the Business Logic Unit
    public JLabel totalBalanceLabel;
    public JTextField withdrawTextField;
    public JTextField depositTextField;
    public JTextField pinTextField;

    /**
     * Creates a new instance of ATMgui
     */
    public ATMgui() {
        setTitle("ATM Transactions");
        setSize(WIDTH, HEIGHT);
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        Container contentPane = getContentPane();
        contentPane.setBackground(Color.BLACK);
        contentPane.setLayout(new BorderLayout());


        // Do the panel for the rest stop
        JLabel start = new JLabel("Welcome To Your Account", JLabel.CENTER);
        Font curFont = start.getFont();
        start.setFont(new Font(curFont.getFontName(), curFont.getStyle(), 25));
        start.setForeground(Color.BLUE);
        start.setOpaque(true);
        start.setBackground(Color.BLACK);


        pinTextField = new JTextField();
        JLabel pinLabel = new JLabel("Enter your PIN below:", JLabel.CENTER);
        pinLabel.setForeground(Color.RED);
        pinLabel.setOpaque(true);
        pinLabel.setBackground(Color.WHITE);



        JButton pinButton = new JButton("Enter Pin OK");
        pinButton.addActionListener(this);
        pinButton.setBackground(Color.red);

        JPanel pinPanel = new JPanel();
        pinPanel.setLayout(new GridLayout(3, 1, 100, 0));

        pinPanel.add(pinLabel);
        pinPanel.add(pinTextField);
        pinPanel.add(pinButton);

        contentPane.add(pinPanel, BorderLayout.WEST);


        JPanel headingPanel = new JPanel();
        headingPanel.setLayout(new GridLayout());
        headingPanel.add(start);

        contentPane.add(headingPanel, BorderLayout.NORTH);


        // Do the panel for the amount & type of transactions
        withdrawTextField = new JTextField();
        JLabel withdrawLabel = new JLabel("Withdraw (0.00)", JLabel.CENTER);
        withdrawLabel.setForeground(Color.RED);
        withdrawLabel.setOpaque(true);
        withdrawLabel.setBackground(Color.WHITE);



        depositTextField = new JTextField();
        JLabel depositLabel = new JLabel("Deposit (0.00)", JLabel.CENTER);
        depositLabel.setForeground(Color.RED);
        depositLabel.setOpaque(true);
        depositLabel.setBackground(Color.WHITE);



        JButton txButton = new JButton("Transactions OK");
        txButton.addActionListener(this);
        txButton.setBackground(Color.red);




        JPanel txPanel = new JPanel();
        txPanel.setLayout(new GridLayout(5, 1, 30, 0));

        txPanel.add(withdrawLabel);
        txPanel.add(withdrawTextField);
        txPanel.add(depositLabel);
        txPanel.add(depositTextField);
        txPanel.add(txButton);

        contentPane.add(txPanel, BorderLayout.EAST);
        txPanel.setVisible(true);


        totalBalanceLabel = new JLabel("Your balance after transactions: ", JLabel.CENTER);
        totalBalanceLabel.setForeground(Color.BLUE);
        totalBalanceLabel.setOpaque(true);
        totalBalanceLabel.setBackground(Color.BLACK);


        contentPane.add(totalBalanceLabel, BorderLayout.SOUTH);


        theBLU = new ATMbizlogic();
    }

    public void actionPerformed(ActionEvent e) {
        String actionCommand = e.getActionCommand();

        // Container contentPane = getContentPane();

        if (actionCommand.equals("Transactions OK")) {
            try {
                double deposit = Double.parseDouble(depositTextField.getText().trim());
                double withdraw = Double.parseDouble(withdrawTextField.getText().trim());
                theBLU.computeBalance(withdraw, deposit);
                totalBalanceLabel.setText("Your balance after transactions: " + theBLU.getBalance());

            } catch (ATMexception ex) {
                totalBalanceLabel.setText("Error: " + ex.getMessage());
            } catch (Exception ex) {
                totalBalanceLabel.setText("Error in deposit or withdraw amount: " + ex.getMessage());
            }
        } else if (actionCommand.equals("Enter Pin OK")) {

            try {

                double pin = Double.parseDouble(pinTextField.getText().trim());
                theBLU.checkPin(pin);

                totalBalanceLabel.setText("Your balance after transactions: " + theBLU.getBalance());



            } catch (ATMexception ex) {
                totalBalanceLabel.setText("Error: " + ex.getMessage());
            } catch (Exception ex) {
                totalBalanceLabel.setText("Error in pin: " + ex.getMessage());

            }
        } else {
            System.out.println("Error in button interface.");
        }
    }

    public static void main(String[] args) {
        ATMgui gui = new ATMgui();
        gui.setVisible(true);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:16:22+00:00Added an answer on May 31, 2026 at 10:16 am

    Since the code pasted by you is not working, I had made a small program for you, have a look, and see what changes can you do to incorporate that in your case :

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class PanelTest extends JFrame
    {
        private JPanel eastPanel;
    
        public PanelTest()
        {
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setLocationByPlatform(true);
    
            Container container = getContentPane();
    
            eastPanel = new JPanel();
            eastPanel.setBackground(Color.DARK_GRAY);
    
            JPanel westPanel = new JPanel();
            westPanel.setBackground(Color.YELLOW);
    
            JPanel centerPanel = new JPanel();
            centerPanel.setBackground(Color.BLUE);
    
            container.add(eastPanel, BorderLayout.LINE_START);
            container.add(centerPanel, BorderLayout.CENTER);
            container.add(westPanel, BorderLayout.LINE_END);
            eastPanel.setVisible(false);
    
            JButton showButton = new JButton("Click Me to Display EAST JPanel");
            showButton.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent ae)
                {
                    eastPanel.setVisible(true);
                }
            });
    
            JButton hideButton = new JButton("Click Me to Hide EAST JPanel");
            hideButton.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent ae)
                {
                    eastPanel.setVisible(false);
                }
            });
    
            container.add(hideButton, BorderLayout.PAGE_START);
            container.add(showButton, BorderLayout.PAGE_END);
    
            setSize(300, 300);
            setVisible(true);
        }
    
        public static void main(String... args)
        {
            SwingUtilities.invokeLater(new Runnable()
            {
                public void run()
                {
                    new PanelTest();
                }
            });
        }
    }
    

    And from future, never use NORTH, EAST, WEST and SOUTH for BorderLayout. They have been replaced with PAGE_START, LINE_START, LINE_END and PAGE_END respectively.

    A BorderLayout object has five areas. These areas are specified by the BorderLayout constants:

    • PAGE_START
    • PAGE_END
    • LINE_START
    • LINE_END
    • CENTER

    Version note:
    Before JDK release 1.4, the preferred names for the various areas were different, ranging from points of the compass (for example, BorderLayout.NORTH for the top area) to wordier versions of the constants we use in our examples. The constants our examples use are preferred because they are standard and enable programs to adjust to languages that have different orientations.

    I had modified the checkPin(...) method of the ATMLogin class to return a boolean instead of void, so that inside the actionPerformed(...) method of the ATMgui class, if this thing returns true, then only to set the required JPanel to visible, else nothing is to be done.

    Do check the code and see what changes you can do to make it work for your end.

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class ATMgui extends JFrame implements ActionListener 
    {
    
        /**
         * 
         */
        private static final long serialVersionUID = 1L;
        public static final int WIDTH = 500;
        public static final int HEIGHT = 200;
        private ATMbizlogic theBLU;// short for the Business Logic Unit
        private JPanel txPanel;
        public JLabel totalBalanceLabel;
        public JTextField withdrawTextField;
        public JTextField depositTextField;
        public JTextField pinTextField;
    
        /**
         * Creates a new instance of ATMgui
         */
        public ATMgui() 
        {
            setTitle("ATM Transactions");
            setSize(WIDTH, HEIGHT);
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            Container contentPane = getContentPane();
            contentPane.setBackground(Color.BLACK);
            contentPane.setLayout(new BorderLayout());
    
    
            // Do the panel for the rest stop
            JLabel start = new JLabel("Welcome To Your Account", JLabel.CENTER);
            Font curFont = start.getFont();
            start.setFont(new Font(curFont.getFontName(), curFont.getStyle(), 25));
            start.setForeground(Color.BLUE);
            start.setOpaque(true);
            start.setBackground(Color.BLACK);
    
    
            pinTextField = new JTextField();
            JLabel pinLabel = new JLabel("Enter your PIN below:", JLabel.CENTER);
            pinLabel.setForeground(Color.RED);
            pinLabel.setOpaque(true);
            pinLabel.setBackground(Color.WHITE);
    
    
    
            JButton pinButton = new JButton("Enter Pin OK");
            pinButton.addActionListener(this);
            pinButton.setBackground(Color.red);
    
            JPanel pinPanel = new JPanel();
            pinPanel.setLayout(new GridLayout(3, 1, 100, 0));
    
            pinPanel.add(pinLabel);
            pinPanel.add(pinTextField);
            pinPanel.add(pinButton);
    
            contentPane.add(pinPanel, BorderLayout.WEST);
    
    
            JPanel headingPanel = new JPanel();
            headingPanel.setLayout(new GridLayout());
            headingPanel.add(start);
    
            contentPane.add(headingPanel, BorderLayout.NORTH);
    
    
            // Do the panel for the amount & type of transactions
            withdrawTextField = new JTextField();
            JLabel withdrawLabel = new JLabel("Withdraw (0.00)", JLabel.CENTER);
            withdrawLabel.setForeground(Color.RED);
            withdrawLabel.setOpaque(true);
            withdrawLabel.setBackground(Color.WHITE);
    
    
    
            depositTextField = new JTextField();
            JLabel depositLabel = new JLabel("Deposit (0.00)", JLabel.CENTER);
            depositLabel.setForeground(Color.RED);
            depositLabel.setOpaque(true);
            depositLabel.setBackground(Color.WHITE);
    
    
    
            JButton txButton = new JButton("Transactions OK");
            txButton.addActionListener(this);
            txButton.setBackground(Color.red);
    
    
    
    
            txPanel = new JPanel();
            txPanel.setLayout(new GridLayout(5, 1, 30, 0));
    
            txPanel.add(withdrawLabel);
            txPanel.add(withdrawTextField);
            txPanel.add(depositLabel);
            txPanel.add(depositTextField);
            txPanel.add(txButton);
    
            contentPane.add(txPanel, BorderLayout.EAST);
            txPanel.setVisible(false);
    
    
            totalBalanceLabel = new JLabel("Your balance after transactions: ", JLabel.CENTER);
            totalBalanceLabel.setForeground(Color.BLUE);
            totalBalanceLabel.setOpaque(true);
            totalBalanceLabel.setBackground(Color.BLACK);
    
    
            contentPane.add(totalBalanceLabel, BorderLayout.SOUTH);
    
    
            theBLU = new ATMbizlogic();
        }
    
        public void actionPerformed(ActionEvent e) 
        {
            String actionCommand = e.getActionCommand();
    
            // Container contentPane = getContentPane();
    
            if (actionCommand.equals("Transactions OK")) 
            {
                try 
                {
                    double deposit = Double.parseDouble(depositTextField.getText().trim());
                    double withdraw = Double.parseDouble(withdrawTextField.getText().trim());
                    theBLU.computeBalance(withdraw, deposit);
                    totalBalanceLabel.setText("Your balance after transactions: " + theBLU.getBalance());
    
                } 
                /*catch (ATMexception ex) 
                {
                    totalBalanceLabel.setText("Error: " + ex.getMessage());
                }*/ 
                catch (Exception ex) 
                {
                    totalBalanceLabel.setText("Error in deposit or withdraw amount: " + ex.getMessage());
                }
            } 
            else if (actionCommand.equals("Enter Pin OK")) 
            {
    
                try 
                {               
                    double pin = Double.parseDouble(pinTextField.getText().trim());
                    if(theBLU.checkPin(pin))
                        txPanel.setVisible(true);
                    totalBalanceLabel.setText("Your balance after transactions: " + theBLU.getBalance());               
                } 
                /*catch (ATMexception ex) 
                {
                    totalBalanceLabel.setText("Error: " + ex.getMessage());
                }*/ 
                catch (Exception ex) 
                {
                    totalBalanceLabel.setText("Error in pin: " + ex.getMessage());
                    ex.printStackTrace();
                }
            } 
            else 
            {
                System.out.println("Error in button interface.");
            }
        }
    
        public static void main(String[] args) 
        {
            ATMgui gui = new ATMgui();
            gui.setVisible(true);
        }
    }
    
    class ATMbizlogic 
    {
    
        private double totalBalance;
        private boolean rightPinEntered;
    
        /**
         * Creates a new instance of ATMbizlogic
         */
        public ATMbizlogic() 
        {
            totalBalance = 0.0;
            rightPinEntered =  true;
        }
    
        public void computeBalance(double withdraw, double deposit)
        //throws ATMexception 
        {
            if(withdraw <=0)
            {
                System.out.println("Negative withdraw not allowed");
                //throw new ATMexception("Negative withdraw not allowed");
            }   
    
            if(deposit <=0)
            {
                System.out.println("Negative deposit not allowed");
                //throw new ATMexception("Negative deposit not allowed");
            }   
    
             double balance = deposit - withdraw;
    
            totalBalance = totalBalance + balance;
        }
    
        public boolean checkPin(double pin)
        //throws ATMexception 
        {
            if(pin <=0)
            {
                System.out.println("Negative pin not allowed");
                rightPinEntered = false;
                //throw new ATMexception("Negative pin not allowed");
            }   
            /*else if(rightPinEntered == false)
            {
                System.out.println("Can not take another pin");
                rightPinEntered = false;
                //throw new ATMexception("Can not take another pin");
            }*/ 
            else if(pin<1111 || pin>9999)
            {
                System.out.println("Enter a valid pin");
                rightPinEntered = false;
                //throw new ATMexception("Enter a valid pin");
            }
            else
            {       
                rightPinEntered = true;
            }
    
            return rightPinEntered;
        }
    
        public double getBalance()
        {
            return totalBalance;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class SuperUser extends User implements Serializable{ private static final long serialVersionUID = 1L;
public class upload extends Activity { private static final int CAMERA_REQUEST = 1888; private
public class BobDatabase extends SQLiteOpenHelper{ private static final String DATABASE_NAME = bob.db; private static
public class PackageTabActivity extends ListActivity{ HashMap<String,Object> hm ; ArrayList<HashMap<String,Object>> applistwithicon ; private static final
public class Sprite { private static final int BMP_COLUMNS = 3; private static final
public class Bird { private static int id = 0; private String kind; public
public class GenericDao <T, PK extends Serializable> { private final Class<T> type; @Resource(name =
public class Bird { private static int id = 0; private String kind; public
public class WordDisplay extends Activity { private int level; private int group; private int
public class WrapperTest { static { print(10); } static void print(int x) { System.out.println(x);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.