0% found this document useful (0 votes)
0 views3 pages

Document

The document is a Java program that creates a simple ATM GUI application using Swing. It allows users to deposit and withdraw money, check their balance, and view transaction history while enforcing input validation for amounts. The application features a user-friendly interface with various buttons and displays the current balance prominently.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views3 pages

Document

The document is a Java program that creates a simple ATM GUI application using Swing. It allows users to deposit and withdraw money, check their balance, and view transaction history while enforcing input validation for amounts. The application features a user-friendly interface with various buttons and displays the current balance prominently.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

import javax.swing.

*;
import java.awt.*;
import java.awt.event.*;

public class Sheesh extends JFrame {

private double balance = 20000;


private JTextField amountField;
private JTextArea historyArea;
private JLabel balanceLabel;

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);

// Top Panel for Balance Display


JPanel topPanel = new JPanel();
topPanel.setBackground(Color.DARK_GRAY);

balanceLabel = new JLabel("Current Balance: P" + String.format("%.2f",


balance));
balanceLabel.setForeground(Color.GREEN);
balanceLabel.setFont(new Font("Arial", Font.BOLD, 25));
topPanel.add(balanceLabel);
add(topPanel, BorderLayout.NORTH);

// Transaction History
historyArea = new JTextArea();
historyArea.setEditable(false);
historyArea.setBackground(Color.BLACK);
historyArea.setForeground(Color.WHITE);
historyArea.setFont(new Font("Monospaced", Font.PLAIN, 14));

JScrollPane scrollPane = new JScrollPane(historyArea);


add(scrollPane, BorderLayout.CENTER);

// Control Positioning for Inputs and Buttons


JPanel controlPanel = new JPanel(new GridLayout(4, 2, 10, 10));
controlPanel.setBackground(Color.BLUE);

// 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);

// Components to control panel


controlPanel.add(amountLabel);
controlPanel.add(amountField);
controlPanel.add(depositButton);
controlPanel.add(withdrawButton);
controlPanel.add(checkBalanceButton);
controlPanel.add(clearButton);

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("");
}

// Flow of Withdraw Phase


private void handleWithdraw() {
try {
double amount = Double.parseDouble(amountField.getText());
if (amount > 0 && amount % 100 == 0) {
if (balance >= amount) {
balance -= amount;
historyArea.append("Withdrawn: P" + String.format("%.2f",
amount) + "\n");
updateBalanceLabel();
} else {
historyArea.append("INSUFFICIENT FUNDS!\n");
}
} 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");
}

// Clear Input and History


private void clearFields() {
amountField.setText("");
historyArea.setText("");
}

// Update Balance Display


private void updateBalanceLabel() {
balanceLabel.setText("Current Balance: P" + String.format("%.2f",
balance));
}

public static void main(String[] args) {


new Sheesh();
}
}

//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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy