-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomerInfoFrame.java
66 lines (50 loc) · 2.24 KB
/
CustomerInfoFrame.java
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
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.*;
public class CustomerInfoFrame extends JFrame implements ActionListener {
private Bank bank;
private JPanel panel = new JPanel(new GridLayout(3, 1));
private JLabel customerField = new JLabel("Enter Customer Username: ");
private JTextField customerTextField = new JTextField();
private JButton checkInfo = new JButton("Check Info");
public CustomerInfoFrame(Bank bank) {
this.bank = bank;
panel.add(customerField);
panel.add(customerTextField);
panel.add(checkInfo);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
checkInfo.addActionListener(this);
add(panel, BorderLayout.CENTER);
setTitle("Customer Details" + " - " + Bank.date);
setSize(600, 150);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
boolean status = false;
String username = customerTextField.getText();
ArrayList<Customer> customers = bank.getCustomers();
for (Customer customer : customers) {
if (username.trim().equals(customer.getUsername().trim())) {
// JOptionPane.showMessageDialog(rootPane, "CUSTOMER IDENTIFIED");
status = true;
StringBuilder str = new StringBuilder();
String name = customer.getUsername();
String totalBalance = customer.showCurrentBalances("dollar").toString();
str.append("Username: " + name + "\n");
str.append("Total Balance ($): " + totalBalance + "\n\n");
str.append("Account Information: \n");
for (Account account : customer.getAccounts()) {
str.append("(" + account.getID() + "): " + account.getAmount() + "\n");
}
String strString = str.toString();
JTextArea accountInfo = new JTextArea(strString);
JOptionPane.showMessageDialog(rootPane, accountInfo);
}
}
if (!status) {
JOptionPane.showMessageDialog(rootPane, "This customer does not exist!");
}
}
}