How can I / where can I add more / better comments and improve the overall Java code structure to enhance its readability and maintainability.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

How can I / where can I add more / better comments and improve the overall Java code structure to enhance its readability and maintainability.

Source code:

package bankAccount;


import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;


public class GUIBankAccount extends JPanel implements ActionListener { //Detects when the user clicks an on screen button on panel.
        //New Jbuttons
        JButton deposit = new JButton("Deposit");
        JButton withdrawal = new JButton("Withdrawal");
        JButton balance = new JButton("Add Balance");
        JButton exit = new JButton("Exit");
        
        TextField depo, withdraw, bal, output; //Text fields
        Label depositAccount, withdrawalAccount, addBalance, balanceTotal; //Labels
        double accountBalance = 0.0; //initializing balance to zero.
        public GUIBankAccount(JFrame frame) {
            //Deposit section.
            //Creating labels, boundaries, text box, action listener and adding them all to frame.
            depositAccount = new Label("Deposit");
            depositAccount.setBounds(90, 115, 60, 50);
            frame.add(depositAccount);
            
            depo = new TextField("");
            depo.setBounds(150, 125, 150, 30);
            frame.add(depo);
            
            deposit.addActionListener(this);
            deposit.setBounds(450, 125, 150, 30);
            frame.add(deposit);
            
            withdrawalAccount = new Label("Withdrawal");
            withdrawalAccount.setBounds(80, 190, 60, 50);
            frame.add(withdrawalAccount);
            
            withdraw = new TextField("");
            withdraw.setBounds(150, 200, 150, 30);
            frame.add(withdraw);
            
            withdrawal.addActionListener(this);
            withdrawal.setBounds(450, 200, 150, 30);
            frame.add(withdrawal);


            addBalance = new Label("Add Balance");
            addBalance.setBounds(70, 40, 70, 30);
            frame.add(addBalance);
            
            bal = new TextField("");
            bal.setBounds(150, 40, 150, 30);
            frame.add(bal);
            
            balance.addActionListener(this);
            balance.setBounds(450, 40, 150, 30);
            frame.add(balance);
            
            balanceTotal = new Label("Balance");
            balanceTotal.setBounds(90, 280, 60, 30);
            frame.add(balanceTotal);
            
            output = new TextField("");
            output.setBounds(150, 280, 150, 30);
            frame.add(output);
            
            exit.addActionListener(this);
            exit.setBounds(450, 280, 150, 30);
            frame.add(exit);
        }
        public static void main(String[] args) {
            JFrame frame = new JFrame();
            frame.getContentPane().add(new GUIBankAccount(frame)); 
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(700, 400);
            frame.setTitle("Bank Account GUI");
            frame.setVisible(true);
        }
        public void actionPerformed(ActionEvent e) {
            if (e.getActionCommand().equals("Deposit")) { 
                System.out.println("Deposit button has been clicked");
                
                String balanceTotal = depo.getText(); //Getting input.
                double depositAccount = Double.parseDouble(balanceTotal); //Method returns a new double initialized to the value.
                
                accountBalance = accountBalance + depositAccount; //Adding funds to balance.
                output.setText(String.valueOf(accountBalance)); //Setting new value
                depo.setText("");//Clearing text in deposit text box.
            }
            //Withdrawal section
            else if (e.getActionCommand().equals("Withdrawal")) {
                System.out.println("Withdrawal button has been clicked");
                
                String balanceTotal = withdraw.getText();
                double withdrawalAccount = Double.parseDouble(balanceTotal);
                
                accountBalance = accountBalance - withdrawalAccount;
                output.setText(String.valueOf(accountBalance));
                withdraw.setText("");
            }
            else if (e.getActionCommand().equals("Add Balance")) {
                System.out.println("Add Balance button has been clicked");
                
                String balanceTotal = bal.getText();
                double addBalance = Double.parseDouble(balanceTotal);
                
                accountBalance = accountBalance + addBalance;
                output.setText(String.valueOf(accountBalance));
                bal.setText("");
            }
            else if(e.getActionCommand().equals("Exit")) {
                System.out.println("User has pressed exit. Good Bye");
                System.exit(0);
            }
        }
    }

Expert Solution
steps

Step by step

Solved in 4 steps with 8 images

Blurred answer
Knowledge Booster
JQuery and Javascript
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education