68 lines
2.2 KiB
Java
68 lines
2.2 KiB
Java
package me.zacharias.bank.app;
|
|
|
|
import me.zacharias.bank.Account;
|
|
import me.zacharias.bank.transaction.Transaction;
|
|
|
|
import javax.swing.*;
|
|
import java.awt.*;
|
|
|
|
public class AccountView extends JPanel {
|
|
|
|
Main bankApplication;
|
|
Account account;
|
|
|
|
JLabel accountName;
|
|
JLabel balance;
|
|
JLabel AccountNumber;
|
|
JList<Transaction> transactionList;
|
|
|
|
public AccountView(Main bankApplication, Account account) {
|
|
this.bankApplication = bankApplication;
|
|
this.account = account;
|
|
|
|
this.setLayout(null);
|
|
|
|
accountName = new JLabel(account.getName());
|
|
accountName.setBounds(10, 10, 200, 30);
|
|
|
|
balance = new JLabel(account.getBalance() + " kr");
|
|
balance.setBounds(10, 50, 200, 30);
|
|
|
|
AccountNumber = new JLabel(account.getId().toString());
|
|
AccountNumber.setBounds(10, 90, 200, 30);
|
|
|
|
transactionList = new JList<>();
|
|
transactionList.setBounds(10, 130, 200, 30);
|
|
transactionList.setModel(new DefaultListModel<>());
|
|
transactionList.setBackground(Color.GRAY);
|
|
transactionList.setCellRenderer(new ListCellRenderer<Transaction>() {
|
|
@Override
|
|
public Component getListCellRendererComponent(JList<? extends Transaction> list, Transaction value, int index, boolean isSelected, boolean cellHasFocus) {
|
|
JButton label = new JButton();
|
|
label.setText(value.getDescription() + " " + value.getAmount() + " kr");
|
|
label.setBackground(Color.GRAY);
|
|
label.addActionListener(e -> {
|
|
bankApplication.showAccount(account);
|
|
});
|
|
return label;
|
|
}
|
|
});
|
|
|
|
this.add(accountName);
|
|
this.add(balance);
|
|
this.add(AccountNumber);
|
|
this.add(transactionList);
|
|
}
|
|
|
|
@Override
|
|
protected void paintComponent(Graphics g) {
|
|
accountName.setBounds(10, 10, 200, 30);
|
|
balance.setBounds(10, 50, 200, 30);
|
|
AccountNumber.setBounds(10, 90, 200, 30);
|
|
transactionList.setBounds(10, 130, 200, 30);
|
|
|
|
transactionList.setListData(account.getTransactions().toArray(new Transaction[0]));
|
|
super.paintComponent(g);
|
|
}
|
|
}
|