forked from hummel/Bank-System
start gui
parent
29ac6122ac
commit
fbdb185b21
|
@ -1,13 +1,15 @@
|
|||
package de.hs_mannheim.informatik.bank;
|
||||
|
||||
import de.hs_mannheim.informatik.bank.facade.Banksystem;
|
||||
import de.hs_mannheim.informatik.bank.gui.GUI;
|
||||
import de.hs_mannheim.informatik.bank.ui.UI;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Banksystem bs = new Banksystem("Spaßkasse Mannheim");
|
||||
UI ui = new UI(bs);
|
||||
//UI ui = new UI(bs);
|
||||
GUI gui = new GUI(bs);
|
||||
}
|
||||
|
||||
}
|
|
@ -39,16 +39,16 @@ public class Konto implements Serializable {
|
|||
kontobewegungen.add(new Kontobewegung(betrag, zweck, art, auftraggeber));
|
||||
}
|
||||
|
||||
public boolean auszahlen(long betrag, String zweck, String art, String auftraggeber) {
|
||||
public boolean auszahlen(long betrag, String zweck, String art, String auftraggeber) throws NotEnoughMoneyException {
|
||||
if (stand - betrag >= 0) {
|
||||
stand -= betrag;
|
||||
|
||||
kontobewegungen.add(new Kontobewegung(betrag * -1, zweck, art, auftraggeber));
|
||||
|
||||
return true;
|
||||
} else {
|
||||
throw new NotEnoughMoneyException();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public String[] getKontobewegungen() {
|
||||
|
|
|
@ -2,6 +2,7 @@ package de.hs_mannheim.informatik.bank.domain;
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class KontoTest {
|
||||
|
@ -25,6 +26,7 @@ class KontoTest {
|
|||
testKontoEinUndAuszahlungUndSaldo(k, k2);
|
||||
}
|
||||
|
||||
|
||||
private void testKontoEinUndAuszahlungUndSaldo(Konto k, Konto k2) {
|
||||
assertEquals("Mayer", k2.getInhaber());
|
||||
assertNotEquals(k.getKontonummer(), k2.getKontonummer());
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package de.hs_mannheim.informatik.bank.domain;
|
||||
|
||||
public class NotEnoughMoneyException extends IllegalArgumentException {
|
||||
|
||||
public NotEnoughMoneyException() {
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,125 @@
|
|||
package de.hs_mannheim.informatik.bank.gui;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.plaf.synth.ColorType;
|
||||
|
||||
import org.w3c.dom.css.RGBColor;
|
||||
|
||||
import de.hs_mannheim.informatik.bank.facade.Banksystem;
|
||||
|
||||
public class GUI {
|
||||
|
||||
private Banksystem bs;
|
||||
|
||||
public GUI(Banksystem bs) {
|
||||
this.bs = bs;
|
||||
hauptmenü();
|
||||
|
||||
}
|
||||
|
||||
private void hauptmenü() {
|
||||
JFrame frame = new JFrame();
|
||||
frame.setSize(500, 500);
|
||||
frame.setTitle(bs.getBankname());
|
||||
frame.setLayout(null);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
JButton getKunde = new JButton("Alle Konten");
|
||||
getKunde.setBounds(100, 50, 300, 50);
|
||||
getKunde.addActionListener(e -> {
|
||||
JFrame allKontos = new JFrame();
|
||||
JPanel alleKontenPanel = new JPanel();
|
||||
allKontos.setTitle(bs.getBankname());
|
||||
allKontos.setSize(500, 500);
|
||||
allKontos.add(alleKontenPanel);
|
||||
String[] konten = bs.getKontenliste();
|
||||
DefaultListModel<String> model = new DefaultListModel<>();
|
||||
if (konten.length > 0) {
|
||||
JLabel labelU = new JLabel("Alle Konten");
|
||||
labelU.setBounds(50, 10, 100, 50);
|
||||
// alleKontenPanel.add(labelU);
|
||||
for (String s : konten) {
|
||||
model.addElement(s);
|
||||
}
|
||||
JList<String> kontenJ = new JList<>(konten);
|
||||
kontenJ.setBackground(new Color(119, 215, 239));
|
||||
// labelU.setBounds(50,50,300,200);
|
||||
alleKontenPanel.add(kontenJ);
|
||||
} else {
|
||||
|
||||
}
|
||||
allKontos.setVisible(true);
|
||||
});
|
||||
frame.add(getKunde);
|
||||
|
||||
JButton kontoAnlegen = new JButton("Konto anlegen");
|
||||
kontoAnlegen.setBounds(100, 120, 300, 50);
|
||||
kontoAnlegen.addActionListener(e -> {
|
||||
|
||||
JFrame kontosAnlegen = new JFrame();
|
||||
JPanel kontenAnlegenPanel = new JPanel();
|
||||
kontosAnlegen.setTitle(bs.getBankname());
|
||||
kontosAnlegen.setSize(500, 500);
|
||||
kontosAnlegen.add(kontenAnlegenPanel);
|
||||
kontenAnlegenPanel.setLayout(null);
|
||||
|
||||
JLabel l_name = new JLabel("Name");
|
||||
l_name.setBounds(50,50,100,50);
|
||||
kontenAnlegenPanel.add(l_name);
|
||||
|
||||
JTextField t_name = new JTextField(20);
|
||||
t_name.setBounds(200,50,100,30);
|
||||
kontenAnlegenPanel.add(t_name);
|
||||
|
||||
JLabel l_konto = new JLabel("Konto");
|
||||
l_konto.setBounds(50,150,100,50);
|
||||
kontenAnlegenPanel.add(l_konto);
|
||||
|
||||
JTextField t_konto = new JTextField(20);
|
||||
t_konto.setBounds(200,150,100,30);
|
||||
kontenAnlegenPanel.add(t_konto);
|
||||
|
||||
JLabel l_kundenNr = new JLabel("Kunden Nummer");
|
||||
l_kundenNr.setBounds(50,250,100,50);
|
||||
kontenAnlegenPanel.add(l_kundenNr);
|
||||
|
||||
JTextField t_kundenNr = new JTextField(20);
|
||||
t_kundenNr.setBounds(200,250,100,30);
|
||||
kontenAnlegenPanel.add(t_kundenNr);
|
||||
|
||||
JButton kundeAnlegen = new JButton("Konto anlegen");
|
||||
kundeAnlegen.setBounds(50,400,350,50);
|
||||
kundeAnlegen.addActionListener(a -> {
|
||||
try {
|
||||
int kontonummer = bs.kontoAnlegen(t_name.getText(), Integer.parseInt(t_konto.getText()),
|
||||
Integer.parseInt(t_kundenNr.getText()));
|
||||
JLabel ko = new JLabel();
|
||||
ko.setBounds(50,350,10,50);
|
||||
ko.setText(Integer.toString(kontonummer));
|
||||
kontenAnlegenPanel.add(ko);
|
||||
} catch (NumberFormatException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
} catch (Exception e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
});
|
||||
kontenAnlegenPanel.add(kundeAnlegen);
|
||||
|
||||
kontosAnlegen.setVisible(true);
|
||||
});
|
||||
frame.add(kontoAnlegen);
|
||||
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue