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;
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;
public class Main {
public static void main(String[] args) throws Exception {
@ -14,8 +11,6 @@ public class Main {
HauptmenüFrame hmf = new HauptmenüFrame(bs);
//GeldEinzahlenFrame gef = new GeldEinzahlenFrame(bs);
}
}

View File

@ -9,7 +9,7 @@ import java.awt.event.ActionEvent;
import de.hs_mannheim.informatik.bank.facade.Banksystem;
public class AuswahlmenüFrame implements ActionListener{
public class AuswahlmenüFrame implements ActionListener {
private JPanel panel;
private JFrame frame;
@ -17,10 +17,11 @@ public class AuswahlmenüFrame implements ActionListener{
private JButton button2;
private JButton button3;
private JButton button4;
private JButton button5;
private Banksystem bs;
public AuswahlmenüFrame(Banksystem bs){
public AuswahlmenüFrame(Banksystem bs) {
this.bs = bs;
@ -50,11 +51,16 @@ public class AuswahlmenüFrame implements ActionListener{
button3.addActionListener(this);
panel.add(button3);
this.button4 = new JButton("Hauptmenü");
this.button4 = new JButton("Geld abheben");
button4.setBounds(40, 140, 300, 25);
button4.addActionListener(this);
panel.add(button4);
this.button5 = new JButton("Hauptmenü");
button5.setBounds(40, 170, 300, 25);
button5.addActionListener(this);
panel.add(button5);
frame.setVisible(true);
}
@ -64,27 +70,31 @@ public class AuswahlmenüFrame implements ActionListener{
System.out.println("Auswahlmenü...");
if(e.getSource() == button) {
if (e.getSource() == button) {
this.frame.dispose();
KontoAnlegenFrame kontoAnlegenFrame = new KontoAnlegenFrame(bs);
}
else if(e.getSource() == button2) {
} else if (e.getSource() == button2) {
this.frame.dispose();
KontoListingFrame kontoListingFrame = new KontoListingFrame(bs);
}
else if(e.getSource() == button3) {
} else if (e.getSource() == button3) {
this.frame.dispose();
GeldEinzahlenFrame geldEinzahlenFrame = new GeldEinzahlenFrame(bs);
}
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();
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

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

@ -10,7 +10,7 @@ import java.awt.event.ActionEvent;
import de.hs_mannheim.informatik.bank.facade.Banksystem;
public class HauptmenüFrame implements ActionListener{
public class HauptmenüFrame implements ActionListener {
private JPanel panel;
private JFrame frame;
@ -19,10 +19,9 @@ public class HauptmenüFrame implements ActionListener{
private JLabel label;
private JLabel label2;
private Banksystem bs;
public HauptmenüFrame(Banksystem bs){
public HauptmenüFrame(Banksystem bs) {
this.bs = bs;
@ -37,7 +36,6 @@ public class HauptmenüFrame implements ActionListener{
frame.add(panel);
panel.setLayout(null);
this.label = new JLabel(bs.getBankname());
label.setBounds(10, 10, 200, 25);
panel.add(label);
@ -65,20 +63,17 @@ public class HauptmenüFrame implements ActionListener{
System.out.println("Hauptmenü...");
if(e.getSource() == button) {
if (e.getSource() == button) {
frame.dispose();
KundeAnlegen kundeAnlegen = new KundeAnlegen(bs);
}
else if(e.getSource() == button2) {
else if (e.getSource() == button2) {
frame.dispose();
LoginFrame loginFrame = new LoginFrame(bs);
frame.dispose();
LoginFrame loginFrame = new LoginFrame(bs);
}

View File

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

View File

@ -8,17 +8,16 @@ import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
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 JButton button;
private JButton button2;
private JTextArea output;
private Banksystem bs;
public KontoListingFrame(Banksystem bs) {
@ -28,35 +27,53 @@ public class KontoListingFrame extends JFrame implements ActionListener{
this.panel = new JPanel();
this.frame = new JFrame();
this.frame.setTitle(bs.getBankname() + " - Kontoliste");
this.frame.setSize(400, 400);
this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.frame.add(panel);
frame.setTitle(bs.getBankname() + " - Kontoliste");
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("Kontoliste abrufen");
this.button.setBounds(10, 80, 160, 25);
this.button.addActionListener(this);
this.panel.add(button);
button.setBounds(10, 10, 160, 25);
button.addActionListener(this);
panel.add(button);
this.output = new JTextArea(20, 20);
this.output.setBounds(10, 110, 300, 200);
this.output.setEditable(false);
this.panel.add(output);
this.button2 = new JButton("Auswahlmenü");
button2.setBounds(215, 10, 260, 25);
button2.addActionListener(this);
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) {
System.out.println("Kontenliste abrufen...");
String[] konten = bs.getKontenlisteForKunde();
if (e.getSource() == button) {
String[] konten = bs.getKontenlisteForKunde();
for (String konto : konten) {
output.append(konto + "\n");
}
} else if (e.getSource() == button2) {
frame.dispose();
AuswahlmenüFrame auswahlmenü = new AuswahlmenüFrame(bs);
for(String konto : konten){
this.output.append(konto + "\n");
}
}
}

View File

@ -12,9 +12,7 @@ import java.awt.event.ActionEvent;
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 JLabel label;
@ -28,18 +26,14 @@ public class KundeAnlegen extends JFrame implements ActionListener{
private JButton button2;
private JTextArea output;
private Banksystem bs;
public KundeAnlegen(Banksystem bs) {
this.bs = bs;
this.panel = new JPanel();
this.frame = new JFrame();
frame.setTitle(bs.getBankname() + " - Kunde anlegen");
frame.setSize(400, 500);
@ -88,32 +82,26 @@ public class KundeAnlegen extends JFrame implements ActionListener{
output.setEditable(false);
panel.add(output);
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Kunde anlegen...");
String name = input.getText();
String surname = input2.getText();
int age = Integer.parseInt(input3.getText());
if (e.getSource() == button) {
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");
input.setText("");
input2.setText("");
input3.setText("");
input.setText("");
input2.setText("");
input3.setText("");
} catch (Exception ex) {
ex.printStackTrace();
@ -126,10 +114,6 @@ public class KundeAnlegen extends JFrame implements ActionListener{
}
}
}

View File

@ -10,7 +10,7 @@ import java.awt.event.ActionListener;
import de.hs_mannheim.informatik.bank.facade.Banksystem;
public class LoginFehlerFrame implements ActionListener{
public class LoginFehlerFrame implements ActionListener {
private JPanel panel;
private JFrame frame;
@ -19,7 +19,6 @@ public class LoginFehlerFrame implements ActionListener{
private Banksystem bs;
public LoginFehlerFrame(Banksystem bs) {
this.bs = bs;
@ -45,18 +44,16 @@ public class LoginFehlerFrame implements ActionListener{
button.addActionListener(this);
panel.add(button);
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Loginfehler...");
if(e.getSource() == button) {
if (e.getSource() == button) {
frame.dispose();
LoginFrame lf = new LoginFrame(bs);
}

View File

@ -11,7 +11,7 @@ import java.awt.event.ActionEvent;
import de.hs_mannheim.informatik.bank.facade.Banksystem;
public class LoginFrame implements ActionListener{
public class LoginFrame implements ActionListener {
private JPanel panel;
private JFrame frame;
@ -21,7 +21,7 @@ public class LoginFrame implements ActionListener{
private Banksystem bs;
public LoginFrame(Banksystem bs){
public LoginFrame(Banksystem bs) {
this.bs = bs;
@ -51,7 +51,6 @@ public class LoginFrame implements ActionListener{
frame.setVisible(true);
}
@Override
@ -61,28 +60,26 @@ public class LoginFrame implements ActionListener{
int kundenID = Integer.parseInt(input.getText());
try {
try {
bs.setCurrentKunde(bs.getKunde(kundenID));
bs.setCurrentKunde(bs.getKunde(kundenID));
if(bs.getCurrentKunde() != null){
if (bs.getCurrentKunde() != null) {
frame.dispose();
AuswahlmenüFrame auswahlmenü = new AuswahlmenüFrame(bs);
frame.dispose();
AuswahlmenüFrame auswahlmenü = new AuswahlmenüFrame(bs);
} else {
} else {
frame.dispose();
LoginFehlerFrame lff = new LoginFehlerFrame(bs);
frame.dispose();
LoginFehlerFrame lff = new LoginFehlerFrame(bs);
}
}
} catch (Exception ex) {
ex.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}