Repository navigation
Expand file tree
/
Copy pathmini.java
More file actions
145 lines (115 loc) · 5.13 KB
/
Copy pathmini.java
File metadata and controls
145 lines (115 loc) · 5.13 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
package bank.management.system;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import java.util.ArrayList;
public class mini extends JFrame implements ActionListener {
String pin_number;
JButton button;
mini(String pin_number) {
this.pin_number = pin_number;
getContentPane().setBackground(new Color(255, 204, 204));
setSize(450, 600);
setLocation(300, 100);
setLayout(null);
JLabel header = new JLabel("Transaction History");
header.setFont(new Font("Arial", Font.BOLD, 18));
header.setForeground(Color.BLACK);
header.setBounds(130, 20, 250, 30);
add(header);
JLabel cardLabel = new JLabel();
cardLabel.setFont(new Font("Arial", Font.BOLD, 14));
cardLabel.setForeground(Color.BLACK);
cardLabel.setBounds(20, 60, 400, 20);
add(cardLabel);
JLabel balanceLabel = new JLabel();
balanceLabel.setFont(new Font("Arial", Font.BOLD, 14));
balanceLabel.setForeground(Color.BLACK);
balanceLabel.setBounds(20, 460, 400, 30);
add(balanceLabel);
// Panel for transactions inside Scroll Pane
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setBackground(Color.WHITE); // White background
JScrollPane scrollPane = new JScrollPane(panel);
scrollPane.setBounds(20, 100, 400, 350);
scrollPane.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
scrollPane.getViewport().setBackground(Color.WHITE);
add(scrollPane);
try {
Connn c = new Connn();
String query = "SELECT l.card_number, b.date, b.type, b.amount FROM login l " +
"JOIN bank b ON l.pin_number = b.pin_number " +
"WHERE l.pin_number = ? ORDER BY b.date ASC";
PreparedStatement stmt = c.connection.prepareStatement(query);
stmt.setString(1, pin_number);
ResultSet resultSet = stmt.executeQuery();
String cardNumber = "";
ArrayList<JPanel> transactionsList = new ArrayList<>();
int balance = 0;
while (resultSet.next()) {
if (cardNumber.isEmpty()) {
cardNumber = resultSet.getString("card_number");
cardLabel.setText("Card Number: " + cardNumber.substring(0, 4) + "XXXXXXXX" + cardNumber.substring(12));
}
String date = resultSet.getString("date");
String type = resultSet.getString("type");
int amount = resultSet.getInt("amount");
// Define color based on transaction type
Color amountColor = type.equals("Deposit") ? new Color(46, 204, 113) : new Color(231, 76, 60); // Green for Deposit, Red for Withdraw
// Create Panel for each transaction
JPanel transactionPanel = new JPanel();
transactionPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
transactionPanel.setBackground(Color.WHITE);
JLabel dateLabel = new JLabel(date + " | ");
dateLabel.setFont(new Font("Arial", Font.PLAIN, 12));
dateLabel.setForeground(Color.BLACK);
JLabel typeLabel = new JLabel(type + " | ");
typeLabel.setFont(new Font("Arial", Font.BOLD, 12));
typeLabel.setForeground(amountColor);
JLabel amountLabel = new JLabel("Rs " + amount);
amountLabel.setFont(new Font("Arial", Font.BOLD, 12));
amountLabel.setForeground(amountColor);
transactionPanel.add(dateLabel);
transactionPanel.add(typeLabel);
transactionPanel.add(amountLabel);
transactionsList.add(transactionPanel);
// Update balance
if (type.equals("Deposit")) {
balance += amount;
} else {
balance -= amount;
}
}
// Show only last 10 transactions
if (transactionsList.size() > 10) {
transactionsList = new ArrayList<>(transactionsList.subList(transactionsList.size() - 10, transactionsList.size()));
}
for (JPanel transactionPanel : transactionsList) {
panel.add(transactionPanel);
}
balanceLabel.setText("Your Total Balance: Rs " + balance);
stmt.close();
resultSet.close();
} catch (Exception e) {
e.printStackTrace();
}
button = new JButton("Exit");
button.setBounds(160, 520, 100, 30);
button.addActionListener(this);
button.setBackground(Color.BLACK);
button.setForeground(Color.WHITE);
button.setFont(new Font("Arial", Font.BOLD, 14));
add(button);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
setVisible(false);
}
public static void main(String[] args) {
new mini("");
}
}