30 lines
1.0 KiB
Java
30 lines
1.0 KiB
Java
package me.teridax.jcash.gui.transfer;
|
|
|
|
import me.teridax.jcash.banking.accounts.Account;
|
|
import me.teridax.jcash.banking.management.BankingManagementSystem;
|
|
|
|
import static javax.swing.JOptionPane.ERROR_MESSAGE;
|
|
import static javax.swing.JOptionPane.showMessageDialog;
|
|
|
|
public class TransferDialog {
|
|
|
|
public TransferDialog(Account account, BankingManagementSystem bms, Runnable onDeposit) {
|
|
var view = new TransferView();
|
|
var data = new TransferData(bms);
|
|
view.getTransfer().addActionListener(e -> {
|
|
try {
|
|
var amount = view.getAmount();
|
|
|
|
account.takeoff(amount);
|
|
data.transferValue(amount, view.getBlz(), view.getIban());
|
|
onDeposit.run();
|
|
view.dispose();
|
|
} catch (IllegalArgumentException ex) {
|
|
showMessageDialog(null, "invalid account", "Could not transfer", ERROR_MESSAGE);
|
|
}
|
|
});
|
|
view.getCancel().addActionListener(e -> view.dispose());
|
|
view.showDialog();
|
|
}
|
|
}
|