Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am building a GUI for a bank as my project. I have the frame and panel built, but am having trouble with the listeners.

I am building a GUI for a bank as my project. I have the frame and panel built, but am having trouble with the listeners. I am trying to get it so that when you enter the amount you want to withdraw or deposit and click the Balance button, it adds or subtracts the value you entered from your balance.

BankFrame.java

//Date //Author:

import javax.swing.JFrame;

public class BankFrame {

public static void main(String[] args) { //Object with frame title JFrame frame = new JFrame("Meal Selector"); //Close button frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Bankpanel panel = new Bankpanel(); frame.getContentPane().add(panel); //size of frame frame.setSize(500, 1000); //make frame visible frame.setVisible(true);

}

}

Bankpanel.java

//Date: //Author: //Purpose: To display my ability to create and build a Graphic User Interface

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

import java.util.*; import java.text.NumberFormat;

public class BankPanel extends JPanel {

//1. declare instance variables in panel class level // create components private JLabel balanceL, optionL, withdrawL, depositL, remainingL; private JTextField withdraw, deposit, remaining; private JButton balance, Clear; private JRadioButton withdrawR, depositR; //panel constructor BankPanel(){ //List of components //Labels balanceL = new JLabel ("Bank account balance: $5826"); optionL = new JLabel ("Select your option: "); withdrawL = new JLabel ("How much would you like to withdraw?: "); depositL = new JLabel ("How much would you like to deposit?: "); remainingL = new JLabel ("Remaining balance: "); //Text fields withdraw = new JTextField(10); deposit = new JTextField(10); remaining = new JTextField(10); //Buttons balance = new JButton ("Balance"); Clear = new JButton ("Clear"); //Radio buttons (must be grouped together) withdrawR = new JRadioButton("Withdraw"); depositR = new JRadioButton("Deposit"); ButtonGroup transGroup = new ButtonGroup(); transGroup.add(withdrawR); transGroup.add(depositR); //Listeners balance.addActionListener(new remainingListener()); Clear.addActionListener(new ClearListener()); //Adding components to panel add (balanceL); add (optionL); add (withdraw); add (deposit); add (withdrawL); add (withdraw); add (depositL); add (deposit); add (remainingL); add (remaining); add (balance); add (Clear); //Size and background for panel setPreferredSize(new Dimension(500, 1000)); setBackground(Color.blue); } private class remainingListener implements ActionListener { public void actionPerformed (ActionEvent event){ double w, d, r; String withdrawText = withdraw.getText(); String depositText = deposit.getText(); w = Double.parseDouble(withdrawText); d = Double.parseDouble(depositText); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions

Question

18. If you have power, then people will dislike and fear you.

Answered: 1 week ago