-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountFrame.java
More file actions
43 lines (34 loc) · 1.29 KB
/
AccountFrame.java
File metadata and controls
43 lines (34 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package banking.gui;
import banking.model.User;
import banking.service.AccountService;
import javax.swing.*;
import java.awt.*;
import java.sql.Connection;
public class AccountFrame extends JFrame {
private AccountService accountService;
private User user;
public AccountFrame(Connection conn, User user) {
this.user = user;
this.accountService = new AccountService(conn);
setTitle("Account Services - " + user.getUsername());
setSize(400, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
JButton balanceBtn = new JButton("Check Balance");
balanceBtn.addActionListener(e -> {
double balance = accountService.getBalance(user.getId());
JOptionPane.showMessageDialog(this, "Your balance: ₹" + balance);
});
JButton depositBtn = new JButton("Deposit ₹1000");
depositBtn.addActionListener(e -> {
if (accountService.deposit(user.getId(), 1000)) {
JOptionPane.showMessageDialog(this, "Deposited successfully!");
} else {
JOptionPane.showMessageDialog(this, "Deposit failed!");
}
});
add(balanceBtn);
add(depositBtn);
setLocationRelativeTo(null);
}
}