-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankingGUI.java
More file actions
148 lines (128 loc) · 5.19 KB
/
Copy pathBankingGUI.java
File metadata and controls
148 lines (128 loc) · 5.19 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
package banking;
import javax.swing.*;
import java.awt.*;
import java.sql.Connection;
import banking.panels.*;
public class BankingGUI extends JFrame {
public static final String WELCOME_PANEL = "WELCOME";
public static final String LOGIN_PANEL = "LOGIN";
public static final String SIGNUP_PANEL = "SIGNUP";
public static final String DASHBOARD_PANEL = "DASHBOARD";
public static final String TRANSACTION_HISTORY_PANEL = "TRANSACTION_HISTORY";
// Vibrant modern color scheme
public static final Color PRIMARY_COLOR = new Color(79, 70, 229); // Indigo
public static final Color SUCCESS_COLOR = new Color(16, 185, 129); // Emerald
public static final Color DANGER_COLOR = new Color(239, 68, 68); // Red
public static final Color BACKGROUND = new Color(17, 24, 39); // Dark gray
public static final Color CARD_BG = new Color(31, 41, 55); // Card background
public static final Color ACCENT_COLOR = new Color(236, 72, 153); // Pink accent
private CardLayout cardLayout;
private JPanel mainPanel;
private int currentAccountNo = -1;
private String currentUserName = "";
private BankingService service;
private Connection connection;
public BankingGUI() {
setupModernTheme();
initializeConnection();
initializeFrame();
initializePanels();
showPanel(WELCOME_PANEL);
}
private void setupModernTheme() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
UIManager.put("Button.font", new Font("Segoe UI", Font.BOLD, 14));
UIManager.put("Label.font", new Font("Segoe UI", Font.PLAIN, 14));
UIManager.put("TextField.font", new Font("Segoe UI", Font.PLAIN, 14));
UIManager.put("PasswordField.font", new Font("Segoe UI", Font.PLAIN, 14));
} catch (Exception e) {
System.err.println("Could not set theme: " + e.getMessage());
}
}
private void initializeConnection() {
try {
connection = DatabaseConnection.getConnection();
if (connection == null) {
showErrorAndExit("Database Connection Failed",
"Unable to connect to the database. Please check MySQL is running.");
}
service = new BankingService(connection);
System.out.println("Banking service initialized successfully");
} catch (Exception e) {
e.printStackTrace();
showErrorAndExit("Initialization Error",
"Failed to initialize banking service: " + e.getMessage());
}
}
private void initializeFrame() {
setTitle("Bank Management System");
setSize(750, 600);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setResizable(false);
getContentPane().setBackground(BACKGROUND);
}
private void initializePanels() {
cardLayout = new CardLayout();
mainPanel = new JPanel(cardLayout);
mainPanel.setBackground(BACKGROUND);
mainPanel.add(new WelcomePanel(this), WELCOME_PANEL);
mainPanel.add(new LoginPanel(this), LOGIN_PANEL);
mainPanel.add(new SignupPanel(this), SIGNUP_PANEL);
add(mainPanel);
}
public void showTransactionHistory() {
for (Component comp : mainPanel.getComponents()) {
if (comp instanceof TransactionHistoryPanel) {
mainPanel.remove(comp);
break;
}
}
mainPanel.add(new TransactionHistoryPanel(this), TRANSACTION_HISTORY_PANEL);
showPanel(TRANSACTION_HISTORY_PANEL);
}
public void showPanel(String panelName) {
cardLayout.show(mainPanel, panelName);
}
public void showDashboard() {
for (Component comp : mainPanel.getComponents()) {
if (comp instanceof DashboardPanel) {
mainPanel.remove(comp);
break;
}
}
mainPanel.add(new DashboardPanel(this), DASHBOARD_PANEL);
showPanel(DASHBOARD_PANEL);
}
public void resetSession() {
currentAccountNo = -1;
currentUserName = "";
showPanel(WELCOME_PANEL);
}
private void showErrorAndExit(String title, String message) {
JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
private void cleanup() {
try {
if (connection != null && !connection.isClosed()) {
connection.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void dispose() {
cleanup();
super.dispose();
}
public int getCurrentAccountNo() { return currentAccountNo; }
public void setCurrentAccountNo(int accountNo) { this.currentAccountNo = accountNo; }
public String getCurrentUserName() { return currentUserName; }
public void setCurrentUserName(String userName) { this.currentUserName = userName; }
public BankingService getService() { return service; }
public CardLayout getCardLayout() { return cardLayout; }
public JPanel getMainPanel() { return mainPanel; }
}