Implemented Transaction View.
Started Impumenting a Transaction system to create a transaction.
This commit is contained in:
5
src/main/java/me/zacharias/bank/AccountHandler.java
Normal file
5
src/main/java/me/zacharias/bank/AccountHandler.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package me.zacharias.bank;
|
||||
|
||||
public class AccountHandler {
|
||||
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package me.zacharias.bank.app;
|
||||
|
||||
import me.zacharias.bank.Account;
|
||||
import me.zacharias.bank.app.component.DrawManager;
|
||||
import me.zacharias.bank.app.component.InteractiveList;
|
||||
import me.zacharias.bank.transaction.Transaction;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -14,7 +16,7 @@ public class AccountView extends JPanel {
|
||||
JLabel accountName;
|
||||
JLabel balance;
|
||||
JLabel AccountNumber;
|
||||
JList<Transaction> transactionList;
|
||||
InteractiveList<Transaction> transactionList;
|
||||
|
||||
public AccountView(Main bankApplication, Account account) {
|
||||
this.bankApplication = bankApplication;
|
||||
@@ -23,26 +25,24 @@ public class AccountView extends JPanel {
|
||||
this.setLayout(null);
|
||||
|
||||
accountName = new JLabel(account.getName());
|
||||
accountName.setBounds(10, 10, 200, 30);
|
||||
accountName.setBounds(10, 10, 300, 30);
|
||||
|
||||
balance = new JLabel(account.getBalance() + " kr");
|
||||
balance.setBounds(10, 50, 200, 30);
|
||||
balance.setBounds(10, 50, 300, 30);
|
||||
|
||||
AccountNumber = new JLabel(account.getId().toString());
|
||||
AccountNumber.setBounds(10, 90, 200, 30);
|
||||
AccountNumber.setBounds(10, 90, 300, 30);
|
||||
|
||||
transactionList = new JList<>();
|
||||
transactionList.setBounds(10, 130, 200, 30);
|
||||
transactionList.setModel(new DefaultListModel<>());
|
||||
transactionList = new InteractiveList<>();
|
||||
transactionList.setBounds(10, 130, 300, 30);
|
||||
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) {
|
||||
transactionList.setDrawManager(new DrawManager<Transaction>() {
|
||||
public Component draw(InteractiveList<Transaction> interactiveList, Transaction value, int index, boolean isHovered, boolean isSelected) {
|
||||
JButton label = new JButton();
|
||||
label.setText(value.getDescription() + " " + value.getAmount() + " kr");
|
||||
label.setBackground(Color.GRAY);
|
||||
label.addActionListener(e -> {
|
||||
bankApplication.showAccount(account);
|
||||
bankApplication.showTransaction(value);
|
||||
});
|
||||
return label;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ public class AccountView extends JPanel {
|
||||
AccountNumber.setBounds(10, 90, 200, 30);
|
||||
transactionList.setBounds(10, 130, 200, 30);
|
||||
|
||||
transactionList.setListData(account.getTransactions().toArray(new Transaction[0]));
|
||||
transactionList.setList(account.getTransactions());
|
||||
super.paintComponent(g);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package me.zacharias.bank.app;
|
||||
|
||||
import me.zacharias.bank.Account;
|
||||
import me.zacharias.bank.User;
|
||||
import me.zacharias.bank.transaction.Transaction;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -15,6 +16,7 @@ public class Main extends JPanel {
|
||||
Login login;
|
||||
MainMenu mainManu;
|
||||
AccountView accountView;
|
||||
TransactionView transactionView;
|
||||
|
||||
Timer timer = new Timer(100, e -> {frame.repaint();});
|
||||
|
||||
@@ -54,4 +56,17 @@ public class Main extends JPanel {
|
||||
frame.add(accountView);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
public void showTransaction(Transaction transaction) {
|
||||
frame.remove(accountView);
|
||||
transactionView = new TransactionView(this, transaction);
|
||||
frame.add(transactionView);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
public void returnFromTransaction() {
|
||||
frame.remove(transactionView);
|
||||
frame.add(accountView);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import me.zacharias.bank.app.component.DrawManager;
|
||||
import me.zacharias.bank.app.component.InteractiveList;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.LineBorder;
|
||||
import java.awt.*;
|
||||
|
||||
public class MainMenu extends JPanel {
|
||||
@@ -34,18 +35,15 @@ public class MainMenu extends JPanel {
|
||||
});
|
||||
|
||||
accountList = new InteractiveList<>();
|
||||
accountList.setBounds(0, 100, getWidth(), getHeight()-200);
|
||||
accountList.setBounds(getWidth()/2-150, 100, 300, 200);
|
||||
accountList.setDrawManager((DrawManager<Account>) (interactiveList, item, index, isHovered, isSelected) -> {
|
||||
JLabel label = new JLabel(item.getName());
|
||||
label.setOpaque(true);
|
||||
label.setBackground(isSelected ? Color.GREEN : Color.WHITE);
|
||||
label.setForeground(isHovered ? Color.WHITE : Color.BLACK);
|
||||
return label;
|
||||
JButton button = new JButton(item.toString());
|
||||
button.addActionListener((a) -> {
|
||||
bankApplication.showAccount(item);
|
||||
});
|
||||
return button;
|
||||
});
|
||||
|
||||
for (Account account : user.getAccounts()) {
|
||||
accountList.add(account);
|
||||
}
|
||||
accountList.setBorder(new LineBorder(Color.BLACK));
|
||||
|
||||
this.add(welcome);
|
||||
this.add(logout);
|
||||
@@ -56,7 +54,7 @@ public class MainMenu extends JPanel {
|
||||
protected void paintComponent(Graphics g) {
|
||||
welcome.setBounds(getWidth()/2-100, 10, 200, 30);
|
||||
logout.setBounds(getWidth()/2-100, getHeight()-50, 200, 30);
|
||||
accountList.setBounds(getWidth()/2-100, getHeight()-80, 200, 300);
|
||||
accountList.setBounds(getWidth()/2-150, 100, 300, 200);
|
||||
|
||||
accountList.setList(user.getAccounts());
|
||||
super.paintComponent(g);
|
||||
|
||||
55
src/main/java/me/zacharias/bank/app/TransactionView.java
Normal file
55
src/main/java/me/zacharias/bank/app/TransactionView.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package me.zacharias.bank.app;
|
||||
|
||||
import me.zacharias.bank.transaction.Transaction;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class TransactionView extends JPanel {
|
||||
Main bankApplication;
|
||||
Transaction transaction;
|
||||
|
||||
JLabel transactionLabel;
|
||||
JLabel amountLabel;
|
||||
JLabel originatingAccountLabel;
|
||||
JLabel destinationAccountLabel;
|
||||
JLabel transactionDateLabel;
|
||||
JLabel transactionTypeLabel;
|
||||
|
||||
JButton backButton;
|
||||
|
||||
public TransactionView(Main bankApplication, Transaction transaction) {
|
||||
this.bankApplication = bankApplication;
|
||||
this.transaction = transaction;
|
||||
|
||||
this.setLayout(null);
|
||||
|
||||
transactionLabel = new JLabel("Description: "+transaction.getDescription());
|
||||
transactionLabel.setBounds(0, 0, 500, 20);
|
||||
|
||||
amountLabel = new JLabel("Amount: "+transaction.getAmount());
|
||||
amountLabel.setBounds(0, 20, 500, 20);
|
||||
|
||||
originatingAccountLabel = new JLabel("Originating account: "+transaction.getOriginator().toString());
|
||||
originatingAccountLabel.setBounds(0, 40, 500, 20);
|
||||
|
||||
destinationAccountLabel = new JLabel("Destination account: "+transaction.getDestination().toString());
|
||||
destinationAccountLabel.setBounds(0, 60, 500, 20);
|
||||
|
||||
transactionDateLabel = new JLabel("Date: "+transaction.getDate());
|
||||
transactionDateLabel.setBounds(0, 80, 500, 20);
|
||||
|
||||
transactionTypeLabel = new JLabel("Type: "+transaction.getType().toString());
|
||||
transactionTypeLabel.setBounds(0, 100, 500, 20);
|
||||
|
||||
backButton = new JButton("Back");
|
||||
backButton.setBounds(0, 120, 500, 20);
|
||||
backButton.addActionListener(e -> bankApplication.returnFromTransaction());
|
||||
|
||||
this.add(transactionLabel);
|
||||
this.add(amountLabel);
|
||||
this.add(originatingAccountLabel);
|
||||
this.add(destinationAccountLabel);
|
||||
this.add(transactionDateLabel);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ public class InteractiveList<T> extends JPanel {
|
||||
return label;
|
||||
}
|
||||
};
|
||||
this.setLayout(null);
|
||||
}
|
||||
|
||||
public void add(T item) {
|
||||
@@ -42,18 +43,23 @@ public class InteractiveList<T> extends JPanel {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setDrawManager(DrawManager drawManager) {
|
||||
public void setDrawManager(DrawManager<T> drawManager) {
|
||||
this.drawManager = drawManager;
|
||||
}
|
||||
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
//Graphics2D g2d = (Graphics2D) g;
|
||||
//g2d.setColor(Color.BLACK);
|
||||
//this.removeAll();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Component component = drawManager.draw(this, list.get(i), i, false, false);
|
||||
component.setBounds(0, i * component.getHeight(), getWidth(), component.getHeight());
|
||||
//add(component);
|
||||
component.paint(g);
|
||||
int h = component.getHeight()==0?20:component.getHeight();
|
||||
component.setBounds(0, i * h, getWidth(), h);
|
||||
//g2d.fillRect(0, i * h, getWidth(), h);
|
||||
add(component);
|
||||
//component.paint(g);
|
||||
}
|
||||
//this.paintChildren(g);
|
||||
super.paintComponent(g);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
package me.zacharias.bank.transaction;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Transaction {
|
||||
double amount;
|
||||
String description;
|
||||
UUID originator;
|
||||
UUID destination;
|
||||
TransactionType type;
|
||||
private double amount;
|
||||
private String description;
|
||||
private UUID originator;
|
||||
private UUID destination;
|
||||
private TransactionType type;
|
||||
private String date;
|
||||
|
||||
public Transaction(double amount, String description, UUID destination, UUID originator, TransactionType type) {
|
||||
this.amount = amount;
|
||||
@@ -15,6 +19,7 @@ public class Transaction {
|
||||
this.originator = originator;
|
||||
this.destination = destination;
|
||||
this.type = type;
|
||||
date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm"));
|
||||
}
|
||||
|
||||
public double getAmount() {
|
||||
@@ -36,4 +41,8 @@ public class Transaction {
|
||||
public TransactionType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
return date;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user