Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

design an event handler that will execute when the calcAvailableCreditButton com

ID: 3615774 • Letter: D

Question

design an event handler that will execute when thecalcAvailableCreditButton component is clicked. theevent handler should perform the following: -declare the following real variables: maxCredit, usedCredit, and availableCredit -get a value from a text box named maxCreditTextBoxand assign it to the maxCredit variable -get a value from a text box named usedCreditTextBoxand assign it to the usedCredit variable -subtract the value in usedCredit frommaxCredit and assign the result toavailableCredit -store the value in the availableCredit variable in alabel component named availableCreditLabel design an event handler that will execute when thecalcAvailableCreditButton component is clicked. theevent handler should perform the following: -declare the following real variables: maxCredit, usedCredit, and availableCredit -get a value from a text box named maxCreditTextBoxand assign it to the maxCredit variable -get a value from a text box named usedCreditTextBoxand assign it to the usedCredit variable -subtract the value in usedCredit frommaxCredit and assign the result toavailableCredit -store the value in the availableCredit variable in alabel component named availableCreditLabel -store the value in the availableCredit variable in alabel component named availableCreditLabel

Explanation / Answer

please rate - thanks import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.lang.*; public class creditGUI extends JFrame {private JLabel maxLabel,usedLabel,availableLabel; private JTextField maxf,usedf,availablef; private JButton calcAvailableCreditButton ; private Container pane; private calcButtonHandler cbHandler; private static final int WIDTH= 325; private static final int HEIGHT=250; public creditGUI() {maxLabel=new JLabel("max credit",SwingConstants.RIGHT); usedLabel=new JLabel("used credit",SwingConstants.RIGHT); availableLabel=new JLabel("available credit",SwingConstants.RIGHT); maxf=new JTextField(10); usedf=new JTextField(10); availablef=new JTextField(10); calcAvailableCreditButton=new JButton("get available credit"); cbHandler=new calcButtonHandler(); calcAvailableCreditButton.addActionListener(cbHandler); setTitle("Name Displayer"); pane=getContentPane(); pane.setLayout(new GridLayout(4,2)); pane.add(maxLabel); pane.add(maxf); pane.add(usedLabel); pane.add(usedf); pane.add(availableLabel); pane.add(availablef); pane.add(calcAvailableCreditButton); maxf.setEditable(true); usedf.setEditable(true); availablef.setEditable(false); setSize(WIDTH,HEIGHT); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } private class calcButtonHandler implements ActionListener {public void actionPerformed(ActionEvent e) {double maxCredit,usedCredit,availableCredit; String input; input=maxf.getText(); maxCredit=Double.parseDouble(input); input=usedf.getText(); usedCredit=Double.parseDouble(input); availableCredit=maxCredit-usedCredit; availablef.setText(""+availableCredit); } } public static void main(String[] args) { creditGUI cd = new creditGUI(); } }