-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDashboardPanel.java
More file actions
154 lines (127 loc) · 6.42 KB
/
Copy pathDashboardPanel.java
File metadata and controls
154 lines (127 loc) · 6.42 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package banking.panels;
import javax.swing.*;
import java.awt.*;
import banking.BankingGUI;
import banking.StyledComponents;
import java.sql.ResultSet;
public class DashboardPanel extends JPanel {
public DashboardPanel(BankingGUI app) {
setLayout(new BorderLayout(10, 10));
setBackground(BankingGUI.BACKGROUND);
setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
// Header Panel
JPanel headerPanel = StyledComponents.createGradientPanel(
new Color(41, 128, 185),
new Color(52, 152, 219)
);
headerPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
headerPanel.setLayout(new BorderLayout());
JLabel welcomeLabel = StyledComponents.createStyledLabel(
"Welcome, " + app.getCurrentUserName() + "! 👋",
28,
Font.BOLD
);
welcomeLabel.setForeground(Color.WHITE);
headerPanel.add(welcomeLabel, BorderLayout.WEST);
JLabel accLabel = StyledComponents.createStyledLabel(
"A/C: " + app.getCurrentAccountNo(),
16,
Font.PLAIN
);
accLabel.setForeground(new Color(236, 240, 241));
headerPanel.add(accLabel, BorderLayout.EAST);
// Center Panel with Cards
JPanel centerPanel = new JPanel(new GridLayout(2, 2, 20, 20));
centerPanel.setBackground(BankingGUI.BACKGROUND);
centerPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
JButton balBtn = createDashboardCard("💰 View Balance", "Check your current balance", new Color(52, 152, 219));
JButton transferBtn = createDashboardCard("💸 Transfer Money", "Send money to another account", new Color(155, 89, 182));
JButton historyBtn = createDashboardCard("📊 Transaction History", "View your transactions", new Color(241, 196, 15));
JButton logoutBtn = createDashboardCard("🚪 Logout", "Exit your account", new Color(231, 76, 60));
centerPanel.add(balBtn);
centerPanel.add(transferBtn);
centerPanel.add(historyBtn);
centerPanel.add(logoutBtn);
// Actions
balBtn.addActionListener(e -> {
try {
ResultSet rs = app.getService().getAccount(app.getCurrentAccountNo());
if (rs.next()) {
int balance = rs.getInt("balance");
showBalanceDialog(balance);
}
} catch(Exception ex){
JOptionPane.showMessageDialog(this, "Error fetching balance", "Error", JOptionPane.ERROR_MESSAGE);
}
});
transferBtn.addActionListener(e -> showTransferDialog(app));
historyBtn.addActionListener(e -> {
app.showTransactionHistory();
});
logoutBtn.addActionListener(e -> {
int choice = JOptionPane.showConfirmDialog(this, "Are you sure you want to logout?", "Confirm Logout", JOptionPane.YES_NO_OPTION);
if (choice == JOptionPane.YES_OPTION) {
app.resetSession();
}
});
add(headerPanel, BorderLayout.NORTH);
add(centerPanel, BorderLayout.CENTER);
}
private JButton createDashboardCard(String title, String subtitle, Color bgColor) {
JButton card = new JButton("<html><div style='text-align: center;'><b style='font-size: 18px;'>" +
title + "</b><br><span style='font-size: 12px;'>" + subtitle + "</span></div></html>");
card.setPreferredSize(new Dimension(250, 120));
card.setBackground(bgColor);
card.setForeground(Color.WHITE);
card.setFocusPainted(false);
card.setBorderPainted(false);
card.setOpaque(true);
card.setCursor(new Cursor(Cursor.HAND_CURSOR));
card.setFont(new Font("Segoe UI", Font.PLAIN, 14));
card.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseEntered(java.awt.event.MouseEvent evt) {
card.setBackground(bgColor.brighter());
}
public void mouseExited(java.awt.event.MouseEvent evt) {
card.setBackground(bgColor);
}
});
return card;
}
private void showBalanceDialog(int balance) {
JPanel panel = new JPanel(new BorderLayout(10, 10));
panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
panel.setBackground(Color.WHITE);
JLabel balLabel = new JLabel("₹ " + balance, SwingConstants.CENTER);
balLabel.setFont(new Font("Segoe UI", Font.BOLD, 48));
balLabel.setForeground(new Color(46, 204, 113));
JLabel textLabel = new JLabel("Current Balance", SwingConstants.CENTER);
textLabel.setFont(new Font("Segoe UI", Font.PLAIN, 16));
panel.add(textLabel, BorderLayout.NORTH);
panel.add(balLabel, BorderLayout.CENTER);
JOptionPane.showMessageDialog(this, panel, "Account Balance", JOptionPane.PLAIN_MESSAGE);
}
private void showTransferDialog(BankingGUI app) {
JTextField receiverField = new JTextField(15);
JTextField amountField = new JTextField(15);
JPanel panel = new JPanel(new GridLayout(4, 2, 10, 10));
panel.add(new JLabel("Receiver Account No:"));
panel.add(receiverField);
panel.add(new JLabel("Amount (₹):"));
panel.add(amountField);
int result = JOptionPane.showConfirmDialog(this, panel, "Transfer Money", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
if (result == JOptionPane.OK_OPTION) {
try {
int receiver = Integer.parseInt(receiverField.getText());
int amount = Integer.parseInt(amountField.getText());
if (app.getService().transfer(app.getCurrentAccountNo(), receiver, amount)) {
JOptionPane.showMessageDialog(this, "Transfer Successful! ₹" + amount + " sent.", "Success", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(this, "Transfer Failed. Check account number and balance.", "Failed", JOptionPane.ERROR_MESSAGE);
}
} catch(Exception ex){
JOptionPane.showMessageDialog(this, "Invalid input", "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
}