-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransactionHistoryPanel.java
More file actions
129 lines (110 loc) · 4.91 KB
/
Copy pathTransactionHistoryPanel.java
File metadata and controls
129 lines (110 loc) · 4.91 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
package banking.panels;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.*;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import banking.BankingGUI;
import banking.StyledComponents;
public class TransactionHistoryPanel extends JPanel {
public TransactionHistoryPanel(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(241, 196, 15),
new Color(243, 156, 18)
);
headerPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
headerPanel.setLayout(new BorderLayout());
JLabel titleLabel = StyledComponents.createStyledLabel(
"Transaction History",
28,
Font.BOLD
);
titleLabel.setForeground(Color.WHITE);
headerPanel.add(titleLabel, BorderLayout.WEST);
JLabel accountLabel = StyledComponents.createStyledLabel(
"A/C: " + app.getCurrentAccountNo(),
16,
Font.PLAIN
);
accountLabel.setForeground(new Color(236, 240, 241));
headerPanel.add(accountLabel, BorderLayout.EAST);
// Table Panel
String[] columns = {"Date", "Type", "Account", "Amount", "Status"};
DefaultTableModel model = new DefaultTableModel(columns, 0) {
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
};
JTable table = new JTable(model);
table.setFont(new Font("Segoe UI", Font.PLAIN, 13));
table.setRowHeight(40);
table.setBackground(BankingGUI.CARD_BG);
table.setForeground(new Color(209, 213, 219));
table.setGridColor(new Color(55, 65, 81));
table.setSelectionBackground(new Color(55, 65, 81));
table.setSelectionForeground(Color.WHITE);
table.getTableHeader().setFont(new Font("Segoe UI", Font.BOLD, 14));
table.getTableHeader().setBackground(new Color(31, 41, 55));
table.getTableHeader().setForeground(new Color(209, 213, 219));
table.getTableHeader().setBorder(BorderFactory.createLineBorder(new Color(55, 65, 81)));
// Center align cells
DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
centerRenderer.setHorizontalAlignment(JLabel.CENTER);
for (int i = 0; i < table.getColumnCount(); i++) {
table.getColumnModel().getColumn(i).setCellRenderer(centerRenderer);
}
// Load transaction data
try {
ResultSet rs = app.getService().getTransactionHistory(app.getCurrentAccountNo());
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
while (rs.next()) {
String date = dateFormat.format(rs.getTimestamp("trans_date"));
String type = rs.getString("type");
int otherAccount = rs.getInt("other_account");
int amount = rs.getInt("amount");
String status = type.equals("DEBIT") ? "Sent" : "Received";
model.addRow(new Object[]{
date,
type,
otherAccount,
"₹" + amount,
status
});
}
if (model.getRowCount() == 0) {
model.addRow(new Object[]{"No transactions found", "", "", "", ""});
}
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(this,
"Error loading transaction history",
"Error",
JOptionPane.ERROR_MESSAGE);
}
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setBorder(BorderFactory.createLineBorder(new Color(55, 65, 81), 2));
scrollPane.getViewport().setBackground(BankingGUI.CARD_BG);
// Bottom Panel with Back Button
JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 10));
bottomPanel.setBackground(BankingGUI.BACKGROUND);
JButton backBtn = StyledComponents.createStyledButton(
"Back to Dashboard",
new Color(75, 85, 99),
Color.WHITE,
180,
45
);
backBtn.addActionListener(e -> app.showDashboard());
bottomPanel.add(backBtn);
// Add components
add(headerPanel, BorderLayout.NORTH);
add(scrollPane, BorderLayout.CENTER);
add(bottomPanel, BorderLayout.SOUTH);
}
}