online banking system in java (GUI)

introduction
The Online Banking System project is a secure and feature-rich Java application designed to simulate online banking operations.
Users can register, log in, check balances, transfer funds, and view transaction histories. The admin panel includes account creation, user verification, and monitoring tools.
The GUI ensures a professional and modern banking experience with secure PIN-based authentication. Features like fund transfers, mini statements, and password recovery replicate real-world banking systems. It serves as an excellent educational tool for understanding digital transactions, user authentication, and secure data handling, and can be further expanded with encryption and online payment APIs.
steps to create online banking system
Define banking features — accounts, transactions, balance inquiry.
Design secure login and dashboard GUI.
Create Account and Transaction classes.
Implement authentication and session handling.
Code deposit, withdrawal, transfer methods.
Store data securely in DB.
Add transaction history display.
Test security, transaction flows.
Implement password reset feature.
Final documentation and deployment.
code explanation
1. Imports and Class Declaration
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
public class OnlineBankingSystem extends JFrame {
Imports Java Swing GUI components and event handling.
ArrayList
is used to store transaction logs.Inherits from
JFrame
to create the main application window.
2. Global Variables
CardLayout cardLayout;
JPanel mainPanel;
JTextField usernameField;
JPasswordField passwordField;
JLabel welcomeLabel, balanceLabel;
JTextArea transactionArea;
double balance = 5000.0;
ArrayList transactions = new ArrayList();
GUI components like fields, labels, text areas.
balance
holds the user’s current account balance.transactions
stores deposit/withdrawal records.
3. Constructor
public OnlineBankingSystem() {
...
mainPanel.add(loginPanel(), "Login");
mainPanel.add(dashboardPanel(), "Dashboard");
...
}
Sets up the window.
Uses
CardLayout
to switch between login and dashboard screens.
4. Login Panel
private JPanel loginPanel() {
...
okBtn.addActionListener(e -> {
String user = usernameField.getText();
String pass = new String(passwordField.getPassword());
if (user.equals("admin") && pass.equals("1234")) {
welcomeLabel.setText("Welcome, " + user + "!");
balanceLabel.setText("Balance: ₹" + balance);
cardLayout.show(mainPanel, "Dashboard");
} else {
JOptionPane.showMessageDialog(this, "Invalid Username or Password");
}
});
...
}
Login credentials are hardcoded:
admin
/1234
On success, shows the Dashboard.
Invalid login shows error popup.
5. Dashboard Panel
private JPanel dashboardPanel() {
...
depositBtn.addActionListener(e -> depositMoney());
withdrawBtn.addActionListener(e -> withdrawMoney());
historyBtn.addActionListener(e -> showTransactionHistory());
logoutBtn.addActionListener(e -> {
usernameField.setText("");
passwordField.setText("");
cardLayout.show(mainPanel, "Login");
});
...
}
Buttons & their actions:
Deposit
→ adds money.Withdraw
→ removes money if sufficient.Transaction History
→ displays list of transactions.Logout
→ clears login fields and returns to Login screen.
6. Deposit Function
private void depositMoney() {
String input = JOptionPane.showInputDialog(this, "Enter deposit amount:");
if (input != null) {
try {
double amount = Double.parseDouble(input);
if (amount > 0) {
balance += amount;
transactions.add("Deposited ₹" + amount);
balanceLabel.setText("Balance: ₹" + balance);
JOptionPane.showMessageDialog(this, "₹" + amount + " deposited successfully!");
} else {
JOptionPane.showMessageDialog(this, "Enter a valid positive amount.");
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this, "Invalid input.");
}
}
}
Prompts user to enter an amount.
Validates and updates balance & history.
7. Withdraw Function
private void withdrawMoney() {
String input = JOptionPane.showInputDialog(this, "Enter withdrawal amount:");
if (input != null) {
try {
double amount = Double.parseDouble(input);
if (amount > 0 && amount <= balance) {
balance -= amount;
transactions.add("Withdrew ₹" + amount);
balanceLabel.setText("Balance: ₹" + balance);
JOptionPane.showMessageDialog(this, "₹" + amount + " withdrawn successfully!");
} else {
JOptionPane.showMessageDialog(this, "Invalid amount or insufficient balance.");
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this, "Invalid input.");
}
}
}
Ensures the withdrawal amount is positive and within available balance.
8. Transaction History Function
private void showTransactionHistory() {
if (transactions.isEmpty()) {
JOptionPane.showMessageDialog(this, "No transactions yet.");
return;
}
JTextArea area = new JTextArea();
for (String t : transactions) {
area.append(t + "\n");
}
area.setEditable(false);
JScrollPane scrollPane = new JScrollPane(area);
scrollPane.setPreferredSize(new Dimension(300, 200));
JOptionPane.showMessageDialog(this, scrollPane, "Transaction History", JOptionPane.INFORMATION_MESSAGE);
}
Displays all transaction logs (deposit/withdrawal) in a scrollable area.
9. Main Method
public static void main(String[] args) {
SwingUtilities.invokeLater(OnlineBankingSystem::new);
}
Starts the application in a thread-safe manner using Swing.
source code
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
public class OnlineBankingSystem extends JFrame {
CardLayout cardLayout;
JPanel mainPanel;
JTextField usernameField;
JPasswordField passwordField;
JLabel welcomeLabel, balanceLabel;
JTextArea transactionArea;
double balance = 5000.0;
ArrayList transactions = new ArrayList();
public OnlineBankingSystem() {
setTitle("Online Banking System");
setSize(550, 400);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
cardLayout = new CardLayout();
mainPanel = new JPanel(cardLayout);
mainPanel.add(loginPanel(), "Login");
mainPanel.add(dashboardPanel(), "Dashboard");
add(mainPanel);
cardLayout.show(mainPanel, "Login");
setVisible(true);
}
// 🔐 Login Panel
private JPanel loginPanel() {
JPanel panel = new JPanel(null);
panel.setBackground(new Color(225, 245, 254));
JLabel title = new JLabel("Bank Login", SwingConstants.CENTER);
title.setFont(new Font("Arial", Font.BOLD, 22));
title.setBounds(170, 30, 200, 30);
panel.add(title);
JLabel userLabel = new JLabel("Username:");
userLabel.setBounds(100, 90, 100, 25);
panel.add(userLabel);
usernameField = new JTextField();
usernameField.setBounds(200, 90, 200, 25);
panel.add(usernameField);
JLabel passLabel = new JLabel("Password:");
passLabel.setBounds(100, 130, 100, 25);
panel.add(passLabel);
passwordField = new JPasswordField();
passwordField.setBounds(200, 130, 200, 25);
panel.add(passwordField);
JButton okBtn = new JButton("OK");
okBtn.setBounds(200, 190, 100, 30);
okBtn.setBackground(new Color(30, 136, 229));
okBtn.setForeground(Color.WHITE);
okBtn.addActionListener(e -> {
String user = usernameField.getText();
String pass = new String(passwordField.getPassword());
if (user.equals("admin") && pass.equals("1234")) {
welcomeLabel.setText("Welcome, " + user + "!");
balanceLabel.setText("Balance: ₹" + balance);
cardLayout.show(mainPanel, "Dashboard");
} else {
JOptionPane.showMessageDialog(this, "Invalid Username or Password");
}
});
panel.add(okBtn);
return panel;
}
// 🏦 Dashboard Panel
private JPanel dashboardPanel() {
JPanel panel = new JPanel(null);
panel.setBackground(new Color(232, 245, 233));
welcomeLabel = new JLabel("Welcome!", SwingConstants.CENTER);
welcomeLabel.setFont(new Font("Arial", Font.BOLD, 18));
welcomeLabel.setBounds(150, 20, 250, 30);
panel.add(welcomeLabel);
balanceLabel = new JLabel("Balance: ₹" + balance);
balanceLabel.setFont(new Font("Arial", Font.PLAIN, 16));
balanceLabel.setBounds(180, 60, 200, 25);
panel.add(balanceLabel);
JButton depositBtn = new JButton("Deposit");
depositBtn.setBounds(100, 110, 120, 30);
depositBtn.addActionListener(e -> depositMoney());
panel.add(depositBtn);
JButton withdrawBtn = new JButton("Withdraw");
withdrawBtn.setBounds(280, 110, 120, 30);
withdrawBtn.addActionListener(e -> withdrawMoney());
panel.add(withdrawBtn);
JButton historyBtn = new JButton("Transaction History");
historyBtn.setBounds(160, 160, 200, 30);
historyBtn.addActionListener(e -> showTransactionHistory());
panel.add(historyBtn);
JButton logoutBtn = new JButton("Logout");
logoutBtn.setBounds(200, 220, 120, 30);
logoutBtn.setBackground(Color.LIGHT_GRAY);
logoutBtn.addActionListener(e -> {
usernameField.setText("");
passwordField.setText("");
cardLayout.show(mainPanel, "Login");
});
panel.add(logoutBtn);
return panel;
}
// 💰 Deposit Function
private void depositMoney() {
String input = JOptionPane.showInputDialog(this, "Enter deposit amount:");
if (input != null) {
try {
double amount = Double.parseDouble(input);
if (amount > 0) {
balance += amount;
transactions.add("Deposited ₹" + amount);
balanceLabel.setText("Balance: ₹" + balance);
JOptionPane.showMessageDialog(this, "₹" + amount + " deposited successfully!");
} else {
JOptionPane.showMessageDialog(this, "Enter a valid positive amount.");
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this, "Invalid input.");
}
}
}
// 💸 Withdraw Function
private void withdrawMoney() {
String input = JOptionPane.showInputDialog(this, "Enter withdrawal amount:");
if (input != null) {
try {
double amount = Double.parseDouble(input);
if (amount > 0 && amount <= balance) {
balance -= amount;
transactions.add("Withdrew ₹" + amount);
balanceLabel.setText("Balance: ₹" + balance);
JOptionPane.showMessageDialog(this, "₹" + amount + " withdrawn successfully!");
} else {
JOptionPane.showMessageDialog(this, "Invalid amount or insufficient balance.");
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this, "Invalid input.");
}
}
}
// 📄 Transaction History
private void showTransactionHistory() {
if (transactions.isEmpty()) {
JOptionPane.showMessageDialog(this, "No transactions yet.");
return;
}
JTextArea area = new JTextArea();
for (String t : transactions) {
area.append(t + "\n");
}
area.setEditable(false);
JScrollPane scrollPane = new JScrollPane(area);
scrollPane.setPreferredSize(new Dimension(300, 200));
JOptionPane.showMessageDialog(this, scrollPane, "Transaction History", JOptionPane.INFORMATION_MESSAGE);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(OnlineBankingSystem::new);
}
}
output



