Question
My withdraw and deposit radio buttons are not working and I don't know whats wrong. the radio buttons aren't displaying. BankPanel.java //Date: //Author: //Purpose: To
My withdraw and deposit radio buttons are not working and I don't know whats wrong. the radio buttons aren't displaying.
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.*; 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(450, 1000)); setBackground(Color.red); } public class remainingListener implements ActionListener { public void actionPerformed (ActionEvent event){ double w, d, r; if(event.getSource()==balance){ String withdrawText = withdraw.getText(); String depositText = deposit.getText(); w = Double.parseDouble(withdrawText); d = Double.parseDouble(depositText); //Remaining balance calculation r = 5826 + d - w; //Remaining balance is set to Balance button //You must enter both the deposit and withdraw to get the remaining balance //enter 0 in withdraw if you only want to deposit and vice versa. remaining.setText(String.valueOf(r)); } }} // Clear push button-- listener public class ClearListener implements ActionListener { public void actionPerformed (ActionEvent event){ //clear info from text fields withdraw.setText(""); deposit.setText(""); remaining.setText(""); //clear info from balance label remainingL.setText(""); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started