Document
Document
*;
import java.awt.*;
import java.awt.event.*;
public Sheesh() {
// Frame setup(Default if you open the program)
setTitle("ATM GUI Form");
setSize(600, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
getContentPane().setBackground(Color.BLACK);
// Transaction History
historyArea = new JTextArea();
historyArea.setEditable(false);
historyArea.setBackground(Color.BLACK);
historyArea.setForeground(Color.WHITE);
historyArea.setFont(new Font("Monospaced", Font.PLAIN, 14));
// Input Phase
JLabel amountLabel = new JLabel("Enter Amount:");
amountLabel.setForeground(Color.WHITE);
amountLabel.setFont(new Font("Arial", Font.BOLD, 18));
amountField = new JTextField();
// Creating Buttons
JButton depositButton = new JButton("Deposit");
JButton withdrawButton = new JButton("Withdraw");
JButton checkBalanceButton = new JButton("Check Balance");
JButton clearButton = new JButton("Clear");
// button Designs
depositButton.setBackground(Color.GREEN);
depositButton.setForeground(Color.BLACK);
withdrawButton.setBackground(Color.RED);
withdrawButton.setForeground(Color.WHITE);
checkBalanceButton.setBackground(Color.YELLOW);
checkBalanceButton.setForeground(Color.BLACK);
clearButton.setBackground(Color.CYAN);
clearButton.setForeground(Color.BLACK);
add(controlPanel, BorderLayout.SOUTH);
// Button Terminal
depositButton.addActionListener(event -> handleDeposit());
withdrawButton.addActionListener(event -> handleWithdraw());
checkBalanceButton.addActionListener(event -> checkBalance());
clearButton.addActionListener(event -> clearFields());
setVisible(true);
}
// Deposit Phase and Counter for input of not multiple of 100 and Ltters
or any Character
private void handleDeposit() {
try {
double amount = Double.parseDouble(amountField.getText());
if (amount > 0 && amount % 100 == 0) {
balance += amount;
historyArea.append("Deposited: P" + String.format("%.2f",
amount) + "\n");
updateBalanceLabel();
} else {
historyArea.append("Invalid amount! You must input multiples
of 100.\n");
}
} catch (NumberFormatException ex) {
historyArea.append("Invalid input! Please enter a valid number.\
n");
}
amountField.setText("");
}
// Balance Check
private void checkBalance() {
historyArea.append("Current Balance: P" + String.format("%.2f",
balance) + "\n");
}
//KEY NOTES
//"%.2f"- STRING FORMAT OF ONLY 2 MAXIMUM OF FLOATING POINT
//balance -= amount - THE lONG METHOD OF THAT IS 'BALANCE=BALANCE-AMOUNT'
//balance += amount - THE lONG METHOD OF THAT IS 'BALANCE=BALANCE+AMOUNT'
//append" means to add something to the end of an existing item or list. It is
commonly used when dealing with strings, arrays, or collections.
//historyArea.setEditable(false);- Means you Cant Edit the History of log or
transaction log
//Gridlayout- will do if you want to expand more it will automaticlly adjust or
expand on its own