Fix: added & improved gui's / code refactoring

gui
Caner 2022-12-02 14:33:14 +01:00
parent 6f3e244767
commit d09bf5386f
10 changed files with 325 additions and 205 deletions

View File

@ -1,11 +1,8 @@
package de.hs_mannheim.informatik.bank; package de.hs_mannheim.informatik.bank;
import de.hs_mannheim.informatik.bank.facade.Banksystem; import de.hs_mannheim.informatik.bank.facade.Banksystem;
import de.hs_mannheim.informatik.bank.gui.AuswahlmenüFrame;
import de.hs_mannheim.informatik.bank.gui.GeldEinzahlenFrame;
import de.hs_mannheim.informatik.bank.gui.HauptmenüFrame; import de.hs_mannheim.informatik.bank.gui.HauptmenüFrame;
public class Main { public class Main {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
@ -14,8 +11,6 @@ public class Main {
HauptmenüFrame hmf = new HauptmenüFrame(bs); HauptmenüFrame hmf = new HauptmenüFrame(bs);
//GeldEinzahlenFrame gef = new GeldEinzahlenFrame(bs);
} }
} }

View File

@ -17,6 +17,7 @@ public class AuswahlmenüFrame implements ActionListener{
private JButton button2; private JButton button2;
private JButton button3; private JButton button3;
private JButton button4; private JButton button4;
private JButton button5;
private Banksystem bs; private Banksystem bs;
@ -50,11 +51,16 @@ public class AuswahlmenüFrame implements ActionListener{
button3.addActionListener(this); button3.addActionListener(this);
panel.add(button3); panel.add(button3);
this.button4 = new JButton("Hauptmenü"); this.button4 = new JButton("Geld abheben");
button4.setBounds(40, 140, 300, 25); button4.setBounds(40, 140, 300, 25);
button4.addActionListener(this); button4.addActionListener(this);
panel.add(button4); panel.add(button4);
this.button5 = new JButton("Hauptmenü");
button5.setBounds(40, 170, 300, 25);
button5.addActionListener(this);
panel.add(button5);
frame.setVisible(true); frame.setVisible(true);
} }
@ -64,20 +70,17 @@ public class AuswahlmenüFrame implements ActionListener{
System.out.println("Auswahlmenü..."); System.out.println("Auswahlmenü...");
if (e.getSource() == button) { if (e.getSource() == button) {
this.frame.dispose(); this.frame.dispose();
KontoAnlegenFrame kontoAnlegenFrame = new KontoAnlegenFrame(bs); KontoAnlegenFrame kontoAnlegenFrame = new KontoAnlegenFrame(bs);
} } else if (e.getSource() == button2) {
else if(e.getSource() == button2) {
this.frame.dispose(); this.frame.dispose();
KontoListingFrame kontoListingFrame = new KontoListingFrame(bs); KontoListingFrame kontoListingFrame = new KontoListingFrame(bs);
} } else if (e.getSource() == button3) {
else if(e.getSource() == button3) {
this.frame.dispose(); this.frame.dispose();
GeldEinzahlenFrame geldEinzahlenFrame = new GeldEinzahlenFrame(bs); GeldEinzahlenFrame geldEinzahlenFrame = new GeldEinzahlenFrame(bs);
@ -86,6 +89,13 @@ public class AuswahlmenüFrame implements ActionListener{
else if (e.getSource() == button4) { else if (e.getSource() == button4) {
this.frame.dispose();
GeldAuszahlenFrame geldAuszahlenFrame = new GeldAuszahlenFrame(bs);
}
else if (e.getSource() == button5) {
this.frame.dispose(); this.frame.dispose();
HauptmenüFrame hauptmenüFrame = new HauptmenüFrame(bs); HauptmenüFrame hauptmenüFrame = new HauptmenüFrame(bs);

View File

@ -0,0 +1,138 @@
package de.hs_mannheim.informatik.bank.gui;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.awt.event.ActionEvent;
import de.hs_mannheim.informatik.bank.facade.Banksystem;
public class GeldAuszahlenFrame implements ActionListener{
private JPanel panel;
private JFrame frame;
private JButton button;
private JButton button2;
private JButton button3;
private JTextArea output;
private JTextArea output2;
private JTextField input;
private JTextField input2;
private JLabel label;
private JLabel label2;
private Banksystem bs;
public GeldAuszahlenFrame(Banksystem bs){
this.bs = bs;
this.panel = new JPanel();
this.frame = new JFrame();
frame.setTitle(bs.getBankname() + " - Geld auszahlen");
frame.setSize(500, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.add(panel);
panel.setLayout(null);
this.button = new JButton("Kontostand");
button.setBounds(10, 10, 120, 25);
button.addActionListener(this);
panel.add(button);
this.output = new JTextArea();
output.setBounds(180, 10, 250, 25);
output.setEditable(false);
panel.add(output);
this.label = new JLabel("Kontonummer");
label.setBounds(10, 50, 100, 25);
panel.add(label);
this.input = new JTextField();
input.setBounds(180, 50, 250, 25);
panel.add(input);
this.label2 = new JLabel("Betrag (€)");
label2.setBounds(10, 80, 100, 25);
panel.add(label2);
this.input2 = new JTextField();
input2.setBounds(180, 80, 250, 25);
panel.add(input2);
this.output2 = new JTextArea();
output2.setBounds(25, 170, 435, 165);
output2.setEditable(false);
panel.add(output2);
this.button2 = new JButton("Geld auszahlen");
button2.setBounds(10, 120, 120, 25);
button2.addActionListener(this);
panel.add(button2);
this.button3 = new JButton("Auswahlmenü");
button3.setBounds(355, 120, 120, 25);
button3.addActionListener(this);
panel.add(button3);
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Geld auszahlen...");
if(e.getSource() == button){
long kontostand = bs.getKontostand(Integer.parseInt(input.getText())) / 100;
output.append("Kontostand beträgt " + kontostand + "€");
input.setText("");
}
else if(e.getSource() == button2) {
try {
boolean erfolg = bs.geldAuszahlen(Integer.parseInt(input.getText()), (long) Double.parseDouble(input2.getText()) * 100);
long neuerKontostand = bs.getKontostand(Integer.parseInt(input.getText()));
output2.append("Auszahlung" + ((!erfolg)? " nicht" : "" ) + " erfolgreich.\tneuer Kontostand: " + neuerKontostand / 100 + "€");
input.setText("");
input2.setText("");
} catch (NumberFormatException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
else if(e.getSource() == button3) {
frame.dispose();
AuswahlmenüFrame amf = new AuswahlmenüFrame(bs);
}
}
}

View File

@ -51,7 +51,7 @@ public class GeldEinzahlenFrame implements ActionListener {
input.setBounds(140, 20, 165, 25); input.setBounds(140, 20, 165, 25);
panel.add(input); panel.add(input);
this.label2 = new JLabel("Betrag"); this.label2 = new JLabel("Betrag (€)");
label2.setBounds(10, 50, 80, 25); label2.setBounds(10, 50, 80, 25);
panel.add(label2); panel.add(label2);
@ -71,34 +71,26 @@ public class GeldEinzahlenFrame implements ActionListener {
this.button2 = new JButton("Auswahlmenü"); this.button2 = new JButton("Auswahlmenü");
button2.addActionListener(this); button2.addActionListener(this);
button2.setBounds(40, 380, 300, 25); button2.setBounds(40, 410, 300, 25);
panel.add(button2); panel.add(button2);
this.button3 = new JButton("Haupmenü");
button3.addActionListener(this);
button3.setBounds(40, 410, 300, 25);
panel.add(button3);
frame.setVisible(true); frame.setVisible(true);
} }
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
System.out.println("Geld einzahlen..."); System.out.println("Geld einzahlen...");
int kontonummer = Integer.parseInt(input.getText());
Double betrag = Double.parseDouble(input2.getText());
if (e.getSource() == button) { if (e.getSource() == button) {
try { try {
bs.geldEinzahlen(kontonummer, (long) (betrag * 100)); bs.geldEinzahlen(Integer.parseInt(input.getText()),
output.append("Einzahlung von " + input2.getText() + " erfolgreich\nNeuer Kontostand beträgt " + (bs.getKontostand(Integer.parseInt(input.getText())) / 100) + " €\n"); (long) (Double.parseDouble(input2.getText()) * 100));
output.append("Einzahlung von " + input2.getText() + " erfolgreich\nNeuer Kontostand beträgt "
+ (bs.getKontostand(Integer.parseInt(input.getText())) / 100) + " €\n");
} catch (IOException e1) { } catch (IOException e1) {
e1.printStackTrace(); e1.printStackTrace();
@ -113,13 +105,6 @@ public class GeldEinzahlenFrame implements ActionListener {
} }
else if (e.getSource() == button3) {
frame.dispose();
HauptmenüFrame hmf = new HauptmenüFrame(bs);
}
} }
} }

View File

@ -19,7 +19,6 @@ public class HauptmenüFrame implements ActionListener{
private JLabel label; private JLabel label;
private JLabel label2; private JLabel label2;
private Banksystem bs; private Banksystem bs;
public HauptmenüFrame(Banksystem bs) { public HauptmenüFrame(Banksystem bs) {
@ -37,7 +36,6 @@ public class HauptmenüFrame implements ActionListener{
frame.add(panel); frame.add(panel);
panel.setLayout(null); panel.setLayout(null);
this.label = new JLabel(bs.getBankname()); this.label = new JLabel(bs.getBankname());
label.setBounds(10, 10, 200, 25); label.setBounds(10, 10, 200, 25);
panel.add(label); panel.add(label);
@ -65,9 +63,6 @@ public class HauptmenüFrame implements ActionListener{
System.out.println("Hauptmenü..."); System.out.println("Hauptmenü...");
if (e.getSource() == button) { if (e.getSource() == button) {
frame.dispose(); frame.dispose();

View File

@ -8,21 +8,19 @@ import javax.swing.JFrame;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JTextArea; import javax.swing.JTextArea;
import de.hs_mannheim.informatik.bank.domain.Kontoart; import de.hs_mannheim.informatik.bank.domain.Kontoart;
import de.hs_mannheim.informatik.bank.facade.Banksystem; import de.hs_mannheim.informatik.bank.facade.Banksystem;
public class KontoAnlegenFrame extends JFrame implements ActionListener { public class KontoAnlegenFrame implements ActionListener {
private JPanel panel; private JPanel panel;
private JFrame frame; private JFrame frame;
private JButton button; private JButton button;
private JButton button2; private JButton button2;
private JButton button3; private JButton button3;
private JButton button4;
private JTextArea output; private JTextArea output;
private Banksystem bs; private Banksystem bs;
public KontoAnlegenFrame(Banksystem bs) { public KontoAnlegenFrame(Banksystem bs) {
@ -32,32 +30,40 @@ public class KontoAnlegenFrame extends JFrame implements ActionListener {
this.panel = new JPanel(); this.panel = new JPanel();
this.frame = new JFrame(); this.frame = new JFrame();
this.frame.setTitle(bs.getBankname() + " - Konto anlegen"); frame.setTitle(bs.getBankname() + " - Konto anlegen");
this.frame.setSize(400, 400); frame.setSize(400, 400);
this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.frame.add(panel); frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.add(panel);
panel.setLayout(null);
this.button = new JButton("Girokonto"); this.button = new JButton("Girokonto");
this.button.setBounds(10, 80, 80, 25); button.setBounds(10, 10, 95, 25);
this.button.addActionListener(this); button.addActionListener(this);
this.panel.add(button); panel.add(button);
this.button2 = new JButton("Sparkonto"); this.button2 = new JButton("Sparkonto");
this.button2.setBounds(100, 80, 80, 25); button2.setBounds(145, 10, 95, 25);
this.button2.addActionListener(this); button2.addActionListener(this);
this.panel.add(button2); panel.add(button2);
this.button3 = new JButton("Depot"); this.button3 = new JButton("Depot");
this.button3.setBounds(190, 80, 80, 25); button3.setBounds(280, 10, 95, 25);
this.button3.addActionListener(this); button3.addActionListener(this);
this.panel.add(button3); panel.add(button3);
this.output = new JTextArea(20, 20); this.button4 = new JButton("Auswahlmenü");
this.output.setBounds(10, 110, 300, 200); button4.setBounds(10, 320, 120, 25);
this.output.setEditable(false); button4.addActionListener(this);
this.panel.add(output); panel.add(button4);
this.frame.setVisible(true); this.output = new JTextArea();
output.setBounds(10, 50, 365, 250);
output.setEditable(false);
panel.add(output);
frame.setVisible(true);
} }
@ -65,39 +71,35 @@ public class KontoAnlegenFrame extends JFrame implements ActionListener {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
System.out.println("Konto anlegen..."); System.out.println("Konto anlegen...");
boolean running = true;
while(running) {
try { try {
if (e.getSource() == button) { if (e.getSource() == button) {
bs.kontoAnlegen(bs.getCurrentKunde(), Kontoart.Girokonto);
this.output.append("Girokonto wurde angelegt\n");
running = false;
} else if(e.getSource() == button2) {
bs.kontoAnlegen(bs.getCurrentKunde(), Kontoart.Sparkonto);
this.output.append("Sparkonto wurde angelegt\n");
running = false;
} else if(e.getSource() == button3) {
bs.kontoAnlegen(bs.getCurrentKunde(), Kontoart.Depot);
this.output.append("Depot wurde angelegt\n");
running = false;
}
int kontonummer = bs.kontoAnlegen(bs.getCurrentKunde(), Kontoart.Girokonto);
output.append("Girokonto mit der Kontonummer " + kontonummer + " wurde angelegt\n");
} else if (e.getSource() == button2) {
int kontonummer = bs.kontoAnlegen(bs.getCurrentKunde(), Kontoart.Sparkonto);
output.append("Sparkonto mit der Kontonummer " + kontonummer + " wurde angelegt\n");
} else if (e.getSource() == button3) {
int kontonummer = bs.kontoAnlegen(bs.getCurrentKunde(), Kontoart.Depot);
output.append("Depot mit der Kontonummer " + kontonummer + " wurde angelegt\n");
} else if (e.getSource() == button4) {
frame.dispose();
AuswahlmenüFrame amf = new AuswahlmenüFrame(bs);
}
} }
catch (Exception ex) { catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
running = false;
} }
}
} }

View File

@ -8,17 +8,16 @@ import javax.swing.JFrame;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JTextArea; import javax.swing.JTextArea;
import de.hs_mannheim.informatik.bank.facade.Banksystem; import de.hs_mannheim.informatik.bank.facade.Banksystem;
public class KontoListingFrame extends JFrame implements ActionListener{ public class KontoListingFrame implements ActionListener {
private JPanel panel; private JPanel panel;
private JFrame frame; private JFrame frame;
private JButton button; private JButton button;
private JButton button2;
private JTextArea output; private JTextArea output;
private Banksystem bs; private Banksystem bs;
public KontoListingFrame(Banksystem bs) { public KontoListingFrame(Banksystem bs) {
@ -28,35 +27,53 @@ public class KontoListingFrame extends JFrame implements ActionListener{
this.panel = new JPanel(); this.panel = new JPanel();
this.frame = new JFrame(); this.frame = new JFrame();
this.frame.setTitle(bs.getBankname() + " - Kontoliste"); frame.setTitle(bs.getBankname() + " - Kontoliste");
this.frame.setSize(400, 400); frame.setSize(500, 400);
this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.frame.add(panel); frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.add(panel);
panel.setLayout(null);
this.button = new JButton("Kontoliste abrufen"); this.button = new JButton("Kontoliste abrufen");
this.button.setBounds(10, 80, 160, 25); button.setBounds(10, 10, 160, 25);
this.button.addActionListener(this); button.addActionListener(this);
this.panel.add(button); panel.add(button);
this.output = new JTextArea(20, 20); this.button2 = new JButton("Auswahlmenü");
this.output.setBounds(10, 110, 300, 200); button2.setBounds(215, 10, 260, 25);
this.output.setEditable(false); button2.addActionListener(this);
this.panel.add(output); panel.add(button2);
this.output = new JTextArea();
output.setBounds(10, 60, 465, 280);
output.setEditable(false);
panel.add(output);
this.frame.setVisible(true); frame.setVisible(true);
} }
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
System.out.println("Kontenliste abrufen..."); System.out.println("Kontenliste abrufen...");
if (e.getSource() == button) {
String[] konten = bs.getKontenlisteForKunde(); String[] konten = bs.getKontenlisteForKunde();
for (String konto : konten) { for (String konto : konten) {
this.output.append(konto + "\n"); output.append(konto + "\n");
}
} else if (e.getSource() == button2) {
frame.dispose();
AuswahlmenüFrame auswahlmenü = new AuswahlmenüFrame(bs);
} }
} }
} }

View File

@ -12,8 +12,6 @@ import java.awt.event.ActionEvent;
import de.hs_mannheim.informatik.bank.facade.Banksystem; import de.hs_mannheim.informatik.bank.facade.Banksystem;
public class KundeAnlegen extends JFrame implements ActionListener { public class KundeAnlegen extends JFrame implements ActionListener {
private JPanel panel; private JPanel panel;
@ -28,18 +26,14 @@ public class KundeAnlegen extends JFrame implements ActionListener{
private JButton button2; private JButton button2;
private JTextArea output; private JTextArea output;
private Banksystem bs; private Banksystem bs;
public KundeAnlegen(Banksystem bs) { public KundeAnlegen(Banksystem bs) {
this.bs = bs; this.bs = bs;
this.panel = new JPanel(); this.panel = new JPanel();
this.frame = new JFrame(); this.frame = new JFrame();
frame.setTitle(bs.getBankname() + " - Kunde anlegen"); frame.setTitle(bs.getBankname() + " - Kunde anlegen");
frame.setSize(400, 500); frame.setSize(400, 500);
@ -88,26 +82,20 @@ public class KundeAnlegen extends JFrame implements ActionListener{
output.setEditable(false); output.setEditable(false);
panel.add(output); panel.add(output);
frame.setVisible(true); frame.setVisible(true);
} }
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
System.out.println("Kunde anlegen..."); System.out.println("Kunde anlegen...");
String name = input.getText();
String surname = input2.getText();
int age = Integer.parseInt(input3.getText());
if (e.getSource() == button) { if (e.getSource() == button) {
try { try {
bs.addNewKunde(name, surname, age); bs.addNewKunde(input.getText(), input2.getText(), Integer.parseInt(input3.getText()));
output.append("Ihr Kundenkonto mit der ID [" + bs.getKundenID() + "] wurde erfolgreich angelegt.\n"); output.append("Ihr Kundenkonto mit der ID [" + bs.getKundenID() + "] wurde erfolgreich angelegt.\n");
@ -126,10 +114,6 @@ public class KundeAnlegen extends JFrame implements ActionListener{
} }
} }
} }

View File

@ -19,7 +19,6 @@ public class LoginFehlerFrame implements ActionListener{
private Banksystem bs; private Banksystem bs;
public LoginFehlerFrame(Banksystem bs) { public LoginFehlerFrame(Banksystem bs) {
this.bs = bs; this.bs = bs;
@ -45,12 +44,10 @@ public class LoginFehlerFrame implements ActionListener{
button.addActionListener(this); button.addActionListener(this);
panel.add(button); panel.add(button);
frame.setVisible(true); frame.setVisible(true);
} }
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {

View File

@ -51,7 +51,6 @@ public class LoginFrame implements ActionListener{
frame.setVisible(true); frame.setVisible(true);
} }
@Override @Override
@ -84,5 +83,3 @@ public class LoginFrame implements ActionListener{
} }
} }