-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransactionHistoryScreen.java
More file actions
56 lines (44 loc) · 1.95 KB
/
TransactionHistoryScreen.java
File metadata and controls
56 lines (44 loc) · 1.95 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
import javax.swing.*;
import java.awt.*;
import java.util.List;
/**
* TransactionHistoryScreen class - Screen for viewing transaction history
* Demonstrates: GUI components, JList, Collections Framework
*/
public class TransactionHistoryScreen extends JDialog {
private BankAccount account;
public TransactionHistoryScreen(JFrame parent, BankAccount account) {
super(parent, "Transaction History", true);
this.account = account;
setSize(500, 400);
setLocationRelativeTo(parent);
JPanel mainPanel = new JPanel(new BorderLayout(10, 10));
mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
// Title label
JLabel titleLabel = new JLabel("Transaction History", SwingConstants.CENTER);
titleLabel.setFont(new Font("Arial", Font.BOLD, 18));
mainPanel.add(titleLabel, BorderLayout.NORTH);
// Transaction list
List<Transaction> transactions = account.getTransactionHistory();
DefaultListModel<String> listModel = new DefaultListModel<>();
if (transactions.isEmpty()) {
listModel.addElement("No transaction history available");
} else {
for (Transaction transaction : transactions) {
listModel.addElement(transaction.getFormattedDetails());
}
}
JList<String> transactionList = new JList<>(listModel);
transactionList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
transactionList.setFont(new Font("Monospaced", Font.PLAIN, 12));
JScrollPane scrollPane = new JScrollPane(transactionList);
mainPanel.add(scrollPane, BorderLayout.CENTER);
// Close button
JButton closeButton = new JButton("Close");
closeButton.addActionListener(e -> dispose());
JPanel buttonPanel = new JPanel();
buttonPanel.add(closeButton);
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
add(mainPanel);
}
}