gui #1
|
@ -57,6 +57,7 @@ public final class Main {
|
|||
*/
|
||||
public void showLoginScreen() {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
try {
|
||||
// select db file
|
||||
var path = Loader.load();
|
||||
// read database and login
|
||||
|
@ -66,13 +67,18 @@ public final class Main {
|
|||
login.addAccountSelectionListener(account -> {
|
||||
var profileCont = new AccountController(account);
|
||||
this.window.setContentPane(profileCont.getView());
|
||||
this.window.pack();
|
||||
this.window.revalidate();
|
||||
this.window.repaint();
|
||||
});
|
||||
|
||||
// we are not logged in yet, so show the login prompt on the main window
|
||||
this.window.setContentPane(login.getView());
|
||||
this.window.pack();
|
||||
this.window.setSize(800, 600);
|
||||
this.window.setVisible(true);
|
||||
|
||||
} catch (IllegalStateException e) {
|
||||
System.out.println("no file selected. goodbye");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -51,10 +51,10 @@ public class AccountView extends JPanel {
|
|||
|
||||
this.type.setText(account.getClass().getSimpleName());
|
||||
if (account instanceof Girokonto) {
|
||||
this.typeSpecialLabel.setText("Überziehungsbetrag");
|
||||
this.typeSpecialLabel.setText("Overdraft");
|
||||
this.typeSpecialProperty.setText( StringUtils.LOCAL_NUMBER_FORMAT.format(((Girokonto) account).getOverdraft()) + " €");
|
||||
} else if (account instanceof SavingsAccount) {
|
||||
this.typeSpecialLabel.setText("Zinsbetrag");
|
||||
this.typeSpecialLabel.setText("Interest rate");
|
||||
this.typeSpecialProperty.setText( ((SavingsAccount) account).getInterest() + " %" );
|
||||
}
|
||||
|
||||
|
@ -80,14 +80,14 @@ public class AccountView extends JPanel {
|
|||
accountSelectionPanel.add(iban, BorderLayout.CENTER);
|
||||
accountSelectionPanel.add(accountSelection, BorderLayout.EAST);
|
||||
|
||||
addInputRow(constraints, content, accountSelectionPanel, 1, new JLabel("Kontonummer", SwingConstants.RIGHT));
|
||||
addInputRow(constraints, content, name, 2, new JLabel("Vorname/Nachname", SwingConstants.RIGHT));
|
||||
addInputRow(constraints, content, address, 3, new JLabel("Adresse", SwingConstants.RIGHT));
|
||||
addInputRow(constraints, content, accountSelectionPanel, 1, new JLabel("IBAN", SwingConstants.RIGHT));
|
||||
addInputRow(constraints, content, name, 2, new JLabel("Name/Family-name", SwingConstants.RIGHT));
|
||||
addInputRow(constraints, content, address, 3, new JLabel("Address", SwingConstants.RIGHT));
|
||||
addInputRow(constraints, content, bankName, 4, new JLabel("Bank", SwingConstants.RIGHT));
|
||||
addInputRow(constraints, content, blz, 5, new JLabel("BLZ", SwingConstants.RIGHT));
|
||||
addInputRow(constraints, content, type, 6, new JLabel("Konto", SwingConstants.RIGHT));
|
||||
addInputRow(constraints, content, type, 6, new JLabel("Account", SwingConstants.RIGHT));
|
||||
addInputRow(constraints, content, typeSpecialProperty, 7, typeSpecialLabel);
|
||||
addInputRow(constraints, content, balance, 8, new JLabel("Kontostand", SwingConstants.RIGHT));
|
||||
addInputRow(constraints, content, balance, 8, new JLabel("Balance", SwingConstants.RIGHT));
|
||||
|
||||
var buttonPanel = Box.createHorizontalBox();
|
||||
buttonPanel.add(Box.createHorizontalStrut(4));
|
||||
|
@ -127,10 +127,10 @@ public class AccountView extends JPanel {
|
|||
|
||||
this.content = new JPanel();
|
||||
|
||||
this.logout = new JButton("Abmelden");
|
||||
this.transfer = new JButton("Überweisen");
|
||||
this.deposit = new JButton("Einzahlen");
|
||||
this.takeoff = new JButton("Abheben");
|
||||
this.logout = new JButton("Logout");
|
||||
this.transfer = new JButton("Transfer");
|
||||
this.deposit = new JButton("Deposit");
|
||||
this.takeoff = new JButton("Takeoff");
|
||||
}
|
||||
|
||||
private void addInputRow(GridBagConstraints constraints, JComponent target, JComponent comp, int row, JLabel label) {
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
package me.teridax.jcash.gui.deposit;
|
||||
|
||||
import me.teridax.jcash.banking.Account;
|
||||
import me.teridax.jcash.decode.StringUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.NumberFormatter;
|
||||
import java.awt.*;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.ParseException;
|
||||
import java.util.Locale;
|
||||
|
||||
public class DepositView {
|
||||
|
||||
|
@ -31,70 +30,62 @@ public class DepositView {
|
|||
dialog.setVisible(true);
|
||||
}
|
||||
|
||||
private NumberFormatter getNumberFormat() {
|
||||
var format = NumberFormat.getNumberInstance(Locale.GERMANY);
|
||||
format.setParseIntegerOnly(false);
|
||||
format.setMaximumFractionDigits(2);
|
||||
|
||||
var formatter = new NumberFormatter(format);
|
||||
formatter.setValueClass(Double.class);
|
||||
formatter.setAllowsInvalid(false);
|
||||
|
||||
return formatter;
|
||||
}
|
||||
|
||||
private void layoutComponents() {
|
||||
dialog.getContentPane().setLayout(new GridBagLayout());
|
||||
|
||||
var c = new GridBagConstraints();
|
||||
|
||||
c.gridx = 0;
|
||||
c.gridy = 0;
|
||||
c.weightx = 1;
|
||||
c.weighty = 1;
|
||||
c.fill = GridBagConstraints.BOTH;
|
||||
c.gridwidth = 3;
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
c.anchor = GridBagConstraints.CENTER;
|
||||
c.insets = new Insets(10, 10, 10, 10);
|
||||
c.insets = new Insets(4, 4, 4, 4);
|
||||
dialog.getContentPane().add(new JLabel("Deposit money"), c);
|
||||
|
||||
c.gridx = 0;
|
||||
c.gridy = 1;
|
||||
c.gridwidth = 1;
|
||||
c.fill = GridBagConstraints.NONE;
|
||||
c.anchor = GridBagConstraints.LAST_LINE_END;
|
||||
c.insets = new Insets(10, 10, 10, 10);
|
||||
c.weightx = 0;
|
||||
dialog.getContentPane().add(new JLabel("Betrag", SwingConstants.RIGHT), c);
|
||||
dialog.getContentPane().add(new JLabel("Value", SwingConstants.RIGHT), c);
|
||||
|
||||
c.gridx = 1;
|
||||
c.gridy = 1;
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
c.anchor = GridBagConstraints.LAST_LINE_END;
|
||||
c.insets = new Insets(10, 10, 10, 10);
|
||||
c.weightx = 1;
|
||||
c.weightx = 0.5;
|
||||
dialog.getContentPane().add(value, c);
|
||||
|
||||
c.gridx = 1;
|
||||
c.gridy = 2;
|
||||
c.fill = GridBagConstraints.NONE;
|
||||
c.anchor = GridBagConstraints.LAST_LINE_END;
|
||||
c.insets = new Insets(10, 10, 10, 10);
|
||||
c.weightx = 0;
|
||||
dialog.getContentPane().add(cancel, c);
|
||||
|
||||
c.gridx = 2;
|
||||
c.gridy = 2;
|
||||
c.gridy = 1;
|
||||
c.fill = GridBagConstraints.NONE;
|
||||
c.anchor = GridBagConstraints.LINE_START;
|
||||
c.weightx = 0;
|
||||
dialog.getContentPane().add(new JLabel("€"), c);
|
||||
|
||||
var buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING));
|
||||
buttonPanel.add(cancel);
|
||||
buttonPanel.add(deposit);
|
||||
|
||||
c.gridx = 0;
|
||||
c.gridy = 2;
|
||||
c.gridwidth = 3;
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
c.anchor = GridBagConstraints.LAST_LINE_END;
|
||||
c.insets = new Insets(10, 10, 10, 10);
|
||||
c.weightx = 0;
|
||||
dialog.getContentPane().add(deposit, c);
|
||||
dialog.getContentPane().add(buttonPanel, c);
|
||||
}
|
||||
|
||||
private void createComponents(Account account) {
|
||||
this.dialog = new JDialog();
|
||||
|
||||
this.cancel = new JButton("Abbrechen");
|
||||
this.deposit = new JButton("Einzahlen");
|
||||
this.value = new JFormattedTextField(getNumberFormat());
|
||||
this.cancel = new JButton("Cancel");
|
||||
this.deposit = new JButton("Deposit");
|
||||
this.value = new JFormattedTextField(StringUtils.LOCAL_NUMBER_FORMAT);
|
||||
|
||||
this.dialog.setContentPane(new JPanel(new GridBagLayout()));
|
||||
}
|
||||
|
|
|
@ -4,11 +4,11 @@ import me.teridax.jcash.banking.Account;
|
|||
|
||||
public class TakeoffDialog {
|
||||
|
||||
public TakeoffDialog(Account account, Runnable onDeposit) {
|
||||
public TakeoffDialog(Account account, Runnable onTakeoff) {
|
||||
var view = new TakeoffView(account);
|
||||
view.getDeposit().addActionListener(e -> {
|
||||
view.getTakeoff().addActionListener(e -> {
|
||||
account.takeoff(view.getAmount());
|
||||
onDeposit.run();
|
||||
onTakeoff.run();
|
||||
view.dispose();
|
||||
});
|
||||
view.getCancel().addActionListener(e -> view.dispose());
|
||||
|
|
|
@ -4,11 +4,9 @@ import me.teridax.jcash.banking.Account;
|
|||
import me.teridax.jcash.decode.StringUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.NumberFormatter;
|
||||
import java.awt.*;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.ParseException;
|
||||
import java.util.Locale;
|
||||
|
||||
import static javax.swing.JOptionPane.ERROR_MESSAGE;
|
||||
import static javax.swing.JOptionPane.showMessageDialog;
|
||||
|
@ -17,7 +15,7 @@ public class TakeoffView {
|
|||
|
||||
private JDialog dialog;
|
||||
private JButton cancel;
|
||||
private JButton deposit;
|
||||
private JButton takeoff;
|
||||
private JFormattedTextField value;
|
||||
|
||||
public TakeoffView(Account account) {
|
||||
|
@ -27,7 +25,7 @@ public class TakeoffView {
|
|||
|
||||
public void showDialog() {
|
||||
dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
|
||||
dialog.setTitle("Deposit money");
|
||||
dialog.setTitle("Takeoff money");
|
||||
dialog.pack();
|
||||
dialog.setResizable(false);
|
||||
dialog.setLocationRelativeTo(null);
|
||||
|
@ -36,56 +34,58 @@ public class TakeoffView {
|
|||
}
|
||||
|
||||
private void layoutComponents() {
|
||||
dialog.getContentPane().setLayout(new GridBagLayout());
|
||||
|
||||
var c = new GridBagConstraints();
|
||||
|
||||
c.gridx = 0;
|
||||
c.gridy = 0;
|
||||
c.weightx = 1;
|
||||
c.weighty = 1;
|
||||
c.fill = GridBagConstraints.BOTH;
|
||||
c.gridwidth = 3;
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
c.anchor = GridBagConstraints.CENTER;
|
||||
c.insets = new Insets(10, 10, 10, 10);
|
||||
c.insets = new Insets(4, 4, 4, 4);
|
||||
dialog.getContentPane().add(new JLabel("Takeoff money"), c);
|
||||
|
||||
c.gridx = 0;
|
||||
c.gridy = 1;
|
||||
c.gridwidth = 1;
|
||||
c.fill = GridBagConstraints.NONE;
|
||||
c.anchor = GridBagConstraints.LAST_LINE_END;
|
||||
c.insets = new Insets(10, 10, 10, 10);
|
||||
c.weightx = 0;
|
||||
dialog.getContentPane().add(new JLabel("Betrag", SwingConstants.RIGHT), c);
|
||||
dialog.getContentPane().add(new JLabel("Value", SwingConstants.RIGHT), c);
|
||||
|
||||
c.gridx = 1;
|
||||
c.gridy = 1;
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
c.anchor = GridBagConstraints.LAST_LINE_END;
|
||||
c.insets = new Insets(10, 10, 10, 10);
|
||||
c.weightx = 1;
|
||||
c.weightx = 0.5;
|
||||
dialog.getContentPane().add(value, c);
|
||||
|
||||
c.gridx = 1;
|
||||
c.gridy = 2;
|
||||
c.fill = GridBagConstraints.NONE;
|
||||
c.anchor = GridBagConstraints.LAST_LINE_END;
|
||||
c.insets = new Insets(10, 10, 10, 10);
|
||||
c.weightx = 0;
|
||||
dialog.getContentPane().add(cancel, c);
|
||||
|
||||
c.gridx = 2;
|
||||
c.gridy = 2;
|
||||
c.gridy = 1;
|
||||
c.fill = GridBagConstraints.NONE;
|
||||
c.anchor = GridBagConstraints.LINE_START;
|
||||
c.weightx = 0;
|
||||
dialog.getContentPane().add(new JLabel("€"), c);
|
||||
|
||||
var buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING));
|
||||
buttonPanel.add(cancel);
|
||||
buttonPanel.add(takeoff);
|
||||
|
||||
c.gridx = 0;
|
||||
c.gridy = 2;
|
||||
c.gridwidth = 3;
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
c.anchor = GridBagConstraints.LAST_LINE_END;
|
||||
c.insets = new Insets(10, 10, 10, 10);
|
||||
c.weightx = 0;
|
||||
dialog.getContentPane().add(deposit, c);
|
||||
dialog.getContentPane().add(buttonPanel, c);
|
||||
}
|
||||
|
||||
private void createComponents(Account account) {
|
||||
this.dialog = new JDialog();
|
||||
|
||||
this.cancel = new JButton("Abbrechen");
|
||||
this.deposit = new JButton("Auszahlen");
|
||||
this.cancel = new JButton("Cancel");
|
||||
this.takeoff = new JButton("Takeoff");
|
||||
this.value = new JFormattedTextField(StringUtils.LOCAL_NUMBER_FORMAT);
|
||||
|
||||
this.dialog.setContentPane(new JPanel(new GridBagLayout()));
|
||||
|
@ -108,8 +108,8 @@ public class TakeoffView {
|
|||
return cancel;
|
||||
}
|
||||
|
||||
public JButton getDeposit() {
|
||||
return deposit;
|
||||
public JButton getTakeoff() {
|
||||
return takeoff;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
|
|
Loading…
Reference in New Issue