Started implumenting a GUI for the program.

This commit is contained in:
2025-03-20 13:07:47 +01:00
parent 5f192d1860
commit d8e0c12b9f
11 changed files with 413 additions and 33 deletions

View File

@@ -0,0 +1,67 @@
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);
}
}