Skip to content

Commit 14ead70

Browse files
committed
Initial commit - GUI ATM project
0 parents  commit 14ead70

5 files changed

Lines changed: 311 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.class

ATMgui.jar

4.72 KB
Binary file not shown.

ATMgui.java

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
import javax.swing.*;
2+
import java.awt.*;
3+
import java.awt.event.*;
4+
import java.text.DecimalFormat;
5+
import java.util.*;
6+
7+
public class ATMgui {
8+
private float balance = 0;
9+
private int pin = 1019;
10+
private int pinAttempts = 0;
11+
private HashMap<String, Float> accounts = new HashMap<>();
12+
private ArrayList<String> miniStatement = new ArrayList<>();
13+
private JFrame frame;
14+
15+
// Decimal format for displaying money properly
16+
private DecimalFormat df = new DecimalFormat("#,##0.00");
17+
18+
public ATMgui() {
19+
try {
20+
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
21+
} catch (Exception ignored) {}
22+
23+
accounts.put("12345", 10000f);
24+
accounts.put("67890", 20000f);
25+
showLoginScreen();
26+
}
27+
28+
public void showLoginScreen() {
29+
frame = new JFrame("ATM - Login");
30+
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
31+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
32+
frame.setLayout(new GridBagLayout());
33+
frame.setLocationRelativeTo(null);
34+
35+
GridBagConstraints gbc = new GridBagConstraints();
36+
gbc.insets = new Insets(10, 10, 10, 10);
37+
38+
JLabel label = new JLabel("Enter PIN:");
39+
label.setFont(new Font("Arial", Font.PLAIN, 20));
40+
JPasswordField pinField = new JPasswordField(10);
41+
pinField.setFont(new Font("Arial", Font.PLAIN, 20));
42+
JButton loginBtn = new JButton("Login");
43+
loginBtn.setFont(new Font("Arial", Font.BOLD, 18));
44+
45+
loginBtn.addActionListener(e -> {
46+
String entered = new String(pinField.getPassword());
47+
if (entered.equals(String.valueOf(pin))) {
48+
pinAttempts = 0;
49+
frame.dispose();
50+
showMenu();
51+
} else {
52+
pinAttempts++;
53+
if (pinAttempts >= 3) {
54+
JOptionPane.showMessageDialog(frame, "Too many attempts. Exiting.");
55+
System.exit(0);
56+
} else {
57+
JOptionPane.showMessageDialog(frame, "Incorrect PIN. Attempts left: " + (3 - pinAttempts));
58+
}
59+
}
60+
});
61+
62+
gbc.gridx = 0; gbc.gridy = 0;
63+
frame.add(label, gbc);
64+
gbc.gridx = 1;
65+
frame.add(pinField, gbc);
66+
gbc.gridx = 1; gbc.gridy = 1;
67+
frame.add(loginBtn, gbc);
68+
69+
frame.setVisible(true);
70+
}
71+
72+
public void showMenu() {
73+
frame = new JFrame("ATM - Menu");
74+
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
75+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
76+
frame.setLayout(new GridLayout(7, 1, 20, 20));
77+
frame.setLocationRelativeTo(null);
78+
79+
Font btnFont = new Font("Arial", Font.BOLD, 18);
80+
81+
JButton balanceBtn = new JButton("Check Balance");
82+
JButton depositBtn = new JButton("Deposit");
83+
JButton withdrawBtn = new JButton("Withdraw");
84+
JButton transferBtn = new JButton("Transfer Funds");
85+
JButton miniStmtBtn = new JButton("Mini Statement");
86+
JButton changePinBtn = new JButton("Change PIN");
87+
JButton exitBtn = new JButton("Exit");
88+
89+
for (JButton btn : new JButton[]{balanceBtn, depositBtn, withdrawBtn, transferBtn, miniStmtBtn, changePinBtn, exitBtn}) {
90+
btn.setFont(btnFont);
91+
frame.add(btn);
92+
}
93+
94+
balanceBtn.addActionListener(e -> JOptionPane.showMessageDialog(frame, "Balance: ₹" + df.format(balance)));
95+
depositBtn.addActionListener(e -> deposit());
96+
withdrawBtn.addActionListener(e -> withdraw());
97+
transferBtn.addActionListener(e -> transferFunds());
98+
miniStmtBtn.addActionListener(e -> showMiniStatement());
99+
changePinBtn.addActionListener(e -> changePin());
100+
exitBtn.addActionListener(e -> {
101+
JOptionPane.showMessageDialog(frame, "Thank you for using the ATM!");
102+
System.exit(0);
103+
});
104+
105+
frame.setVisible(true);
106+
}
107+
108+
public void deposit() {
109+
String input = JOptionPane.showInputDialog(frame, "Enter amount to deposit:");
110+
try {
111+
float amount = Float.parseFloat(input);
112+
balance += amount;
113+
miniStatement.add("Deposited: ₹" + df.format(amount));
114+
JOptionPane.showMessageDialog(frame, "Deposit Successful!");
115+
} catch (Exception e) {
116+
JOptionPane.showMessageDialog(frame, "Invalid amount!");
117+
}
118+
}
119+
120+
public void withdraw() {
121+
String input = JOptionPane.showInputDialog(frame, "Enter amount to withdraw:");
122+
try {
123+
float amount = Float.parseFloat(input);
124+
if (amount > balance) {
125+
JOptionPane.showMessageDialog(frame, "Insufficient Balance!");
126+
} else {
127+
balance -= amount;
128+
miniStatement.add("Withdrawn: ₹" + df.format(amount));
129+
JOptionPane.showMessageDialog(frame, "Withdrawal Successful!");
130+
}
131+
} catch (Exception e) {
132+
JOptionPane.showMessageDialog(frame, "Invalid amount!");
133+
}
134+
}
135+
136+
public void transferFunds() {
137+
String acc = JOptionPane.showInputDialog(frame, "Enter recipient account number:");
138+
if (!accounts.containsKey(acc)) {
139+
JOptionPane.showMessageDialog(frame, "Invalid account number!");
140+
return;
141+
}
142+
143+
String input = JOptionPane.showInputDialog(frame, "Enter amount to transfer:");
144+
try {
145+
float amt = Float.parseFloat(input);
146+
if (amt > balance) {
147+
JOptionPane.showMessageDialog(frame, "Insufficient Balance!");
148+
return;
149+
}
150+
balance -= amt;
151+
accounts.put(acc, accounts.get(acc) + amt);
152+
miniStatement.add("Transferred ₹" + df.format(amt) + " to Acc: " + acc);
153+
JOptionPane.showMessageDialog(frame, "Transfer Successful!");
154+
} catch (Exception e) {
155+
JOptionPane.showMessageDialog(frame, "Invalid amount!");
156+
}
157+
}
158+
159+
public void showMiniStatement() {
160+
if (miniStatement.isEmpty()) {
161+
JOptionPane.showMessageDialog(frame, "No transactions yet.");
162+
return;
163+
}
164+
StringBuilder sb = new StringBuilder();
165+
for (String t : miniStatement) {
166+
sb.append(t).append("\n");
167+
}
168+
sb.append("\nCurrent Balance: ₹").append(df.format(balance));
169+
JTextArea textArea = new JTextArea(sb.toString());
170+
textArea.setEditable(false);
171+
textArea.setFont(new Font("Monospaced", Font.PLAIN, 14));
172+
JOptionPane.showMessageDialog(frame, new JScrollPane(textArea), "Mini Statement", JOptionPane.INFORMATION_MESSAGE);
173+
}
174+
175+
public void changePin() {
176+
String oldPin = JOptionPane.showInputDialog(frame, "Enter current PIN:");
177+
if (!oldPin.equals(String.valueOf(pin))) {
178+
JOptionPane.showMessageDialog(frame, "Incorrect current PIN!");
179+
return;
180+
}
181+
182+
String newPin = JOptionPane.showInputDialog(frame, "Enter new PIN:");
183+
String reNew = JOptionPane.showInputDialog(frame, "Re-enter new PIN:");
184+
if (newPin.equals(reNew)) {
185+
pin = Integer.parseInt(newPin);
186+
JOptionPane.showMessageDialog(frame, "PIN changed successfully!");
187+
} else {
188+
JOptionPane.showMessageDialog(frame, "PINs do not match!");
189+
}
190+
}
191+
192+
public static void main(String[] args) {
193+
SwingUtilities.invokeLater(ATMgui::new);
194+
}
195+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Nilesh Palve
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# 💳 ATM Machine Simulation (Java GUI Project)
2+
3+
![Java](https://img.shields.io/badge/Java-19-blue.svg)
4+
![Platform](https://img.shields.io/badge/Platform-GUI--App-lightgrey)
5+
![Status](https://img.shields.io/badge/Status-Completed-brightgreen)
6+
![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)
7+
8+
This is a **Graphical User Interface (GUI)** based ATM simulation system built using **Java Swing**. The application simulates basic banking operations such as deposit, withdrawal, balance check, fund transfer, PIN change, and mini statement functionality with full-screen UI.
9+
10+
---
11+
12+
## 🚀 Features
13+
14+
- ✅ PIN-based login with limited attempts
15+
- 💵 Deposit money
16+
- 💸 Withdraw money with validation
17+
- 📋 View mini statement
18+
- 🔁 Transfer funds to other simulated accounts
19+
- 🔐 Change PIN securely
20+
- 📐 Full-screen GUI layout using Swing
21+
- 🪟 Centered components with formatted currency output
22+
23+
---
24+
25+
## 🧰 Technologies Used
26+
27+
- Java (JDK 19)
28+
- Java Swing (GUI)
29+
- `ArrayList`, `HashMap` (Collections Framework)
30+
- `JOptionPane`, `JFrame`, `JPanel`, `JButton`, etc.
31+
- `DecimalFormat` for currency formatting
32+
33+
---
34+
35+
## 📂 Project Structure
36+
37+
```
38+
ATM-Machine-GUI/
39+
├── ATMgui.java # Main GUI Java file
40+
├── README.md # Project documentation
41+
└── LICENSE # (Optional) MIT License
42+
```
43+
44+
---
45+
46+
## ▶️ How to Run
47+
48+
### 🔧 Prerequisites
49+
- Java JDK 19 installed and configured in your system PATH
50+
- Java-compatible editor (e.g., VS Code, IntelliJ, NetBeans)
51+
52+
### 💻 Compile the code:
53+
```bash
54+
javac ATMgui.java
55+
```
56+
57+
### 🚀 Run the application:
58+
```bash
59+
java ATMgui
60+
```
61+
62+
---
63+
64+
## 🖼 GUI Preview
65+
66+
> The application launches in full screen
67+
> All ATM options are accessible via buttons
68+
> Popups are used for input and feedback
69+
> Balances appear formatted (e.g., ₹10,000.00)
70+
71+
---
72+
73+
## 📦 Future Enhancements
74+
75+
- [ ] Export mini statement to file
76+
- [ ] Store account and transaction data persistently
77+
- [ ] Add user login system with account registration
78+
- [ ] Package as `.jar` for easy sharing and launch
79+
80+
---
81+
82+
## 📜 License
83+
84+
This project is licensed under the **MIT License**.
85+
See the [`LICENSE`](LICENSE) file for details.
86+
87+
---
88+
89+
## 🙋‍♂️ Author
90+
91+
**Nilesh Palve**
92+
📧 [palvenileshp@gmail.com](mailto:palvenileshp@gmail.com)
93+
94+
---

0 commit comments

Comments
 (0)