Fix: improved gui & code refactoring

gui
Caner 2022-12-02 13:09:54 +01:00
parent 930c6b96b3
commit 6f3e244767
7 changed files with 244 additions and 134 deletions

View File

@ -1,8 +1,9 @@
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;
import de.hs_mannheim.informatik.bank.gui.KundeAnlegen;
public class Main {
@ -11,9 +12,9 @@ public class Main {
Banksystem bs = new Banksystem("Spaßkasse Mannheim");
//HauptmenüFrame hmf = new HauptmenüFrame(bs);
HauptmenüFrame hmf = new HauptmenüFrame(bs);
KundeAnlegen ka = new KundeAnlegen(bs);
//GeldEinzahlenFrame gef = new GeldEinzahlenFrame(bs);
}

View File

@ -9,13 +9,14 @@ import java.awt.event.ActionEvent;
import de.hs_mannheim.informatik.bank.facade.Banksystem;
public class AuswahlmenüFrame extends JFrame implements ActionListener{
public class AuswahlmenüFrame implements ActionListener{
private JPanel panel;
private JFrame frame;
private JButton button;
private JButton button2;
private JButton button3;
private JButton button4;
private Banksystem bs;
@ -26,29 +27,35 @@ public class AuswahlmenüFrame extends JFrame implements ActionListener{
this.panel = new JPanel();
this.frame = new JFrame();
this.frame.setTitle(bs.getBankname() + " - Auswahlmenü");
this.frame.setSize(400, 400);
this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.frame.add(panel);
this.panel.setLayout(null);
frame.setTitle(bs.getBankname() + " - Auswahlmenü");
frame.setSize(400, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.add(panel);
panel.setLayout(null);
this.button = new JButton("Konto anlegen");
this.button.setBounds(10, 80, 300, 25);
this.button.addActionListener(this);
this.panel.add(button);
button.setBounds(40, 50, 300, 25);
button.addActionListener(this);
panel.add(button);
this.button2 = new JButton("Konten auflisten");
this.button2.setBounds(10, 110, 300, 25);
this.button2.addActionListener(this);
this.panel.add(button2);
button2.setBounds(40, 80, 300, 25);
button2.addActionListener(this);
panel.add(button2);
this.button3 = new JButton("Geld einzahlen");
this.button3.setBounds(10, 140, 300, 25);
this.button3.addActionListener(this);
this.panel.add(button3);
button3.setBounds(40, 110, 300, 25);
button3.addActionListener(this);
panel.add(button3);
this.frame.setVisible(true);
this.button4 = new JButton("Hauptmenü");
button4.setBounds(40, 140, 300, 25);
button4.addActionListener(this);
panel.add(button4);
frame.setVisible(true);
}
@ -56,30 +63,34 @@ public class AuswahlmenüFrame extends JFrame implements ActionListener{
public void actionPerformed(ActionEvent e) {
System.out.println("Auswahlmenü...");
boolean running = true;
while(running) {
if(e.getSource() == button) {
if(e.getSource() == button) {
this.frame.dispose();
KontoAnlegenFrame kontoAnlegenFrame = new KontoAnlegenFrame(bs);
running = false;
}
else if(e.getSource() == button2) {
this.frame.dispose();
KontoListingFrame kontoListingFrame = new KontoListingFrame(bs);
running = false;
}
else if(e.getSource() == button3) {
this.frame.dispose();
GeldEinzahlenFrame geldEinzahlenFrame = new GeldEinzahlenFrame(bs);
running = false;
}
this.frame.dispose();
KontoAnlegenFrame kontoAnlegenFrame = new KontoAnlegenFrame(bs);
}
else if(e.getSource() == button2) {
this.frame.dispose();
KontoListingFrame kontoListingFrame = new KontoListingFrame(bs);
}
else if(e.getSource() == button3) {
this.frame.dispose();
GeldEinzahlenFrame geldEinzahlenFrame = new GeldEinzahlenFrame(bs);
}
else if(e.getSource() == button4) {
this.frame.dispose();
HauptmenüFrame hauptmenüFrame = new HauptmenüFrame(bs);
}
}
}

View File

@ -8,11 +8,12 @@ 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 GeldEinzahlenFrame extends JFrame implements ActionListener {
public class GeldEinzahlenFrame implements ActionListener {
private JPanel panel;
private JFrame frame;
@ -22,6 +23,8 @@ public class GeldEinzahlenFrame extends JFrame implements ActionListener {
private JTextField input2;
private JTextArea output;
private JButton button;
private JButton button2;
private JButton button3;
private Banksystem bs;
@ -32,39 +35,51 @@ public class GeldEinzahlenFrame extends JFrame implements ActionListener {
this.panel = new JPanel();
this.frame = new JFrame();
this.frame.setTitle(bs.getBankname() + " - Geld einzahlen");
this.frame.setSize(400, 400);
this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.frame.add(panel);
this.panel.setLayout(null);
frame.setTitle(bs.getBankname() + " - Geld einzahlen");
frame.setSize(400, 480);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.add(panel);
panel.setLayout(null);
this.label = new JLabel("Kontonummer");
label.setBounds(10, 20, 80, 25);
this.panel.add(label);
label.setBounds(10, 20, 100, 25);
panel.add(label);
this.input = new JTextField(20);
this.input.setBounds(100, 20, 165, 25);
this.panel.add(input);
input.setBounds(140, 20, 165, 25);
panel.add(input);
this.label2 = new JLabel("Betrag");
label2.setBounds(10, 50, 80, 25);
this.panel.add(label2);
panel.add(label2);
this.input2 = new JTextField(20);
this.input2.setBounds(100, 50, 165, 25);
this.panel.add(input2);
input2.setBounds(140, 50, 165, 25);
panel.add(input2);
this.output = new JTextArea();
this.output.setBounds(10, 110, 300, 200);
this.output.setEditable(false);
this.panel.add(output);
output.setBounds(40, 100, 300, 200);
output.setEditable(false);
panel.add(output);
this.button = new JButton("Einzahlen");
button.addActionListener(this);
button.setBounds(10, 320, 300, 25);
this.panel.add(button);
button.setBounds(40, 305, 300, 25);
panel.add(button);
this.frame.setVisible(true);
this.button2 = new JButton("Auswahlmenü");
button2.addActionListener(this);
button2.setBounds(40, 380, 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);
}
@ -73,21 +88,38 @@ public class GeldEinzahlenFrame extends JFrame implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.out.println("Geld einzahlen...");
int kontonummer = Integer.parseInt(input.getText());
Double betrag = Double.parseDouble(input2.getText());
try {
bs.geldEinzahlen(Integer.parseInt(input.getText()), (long) (betrag * 100));
this.output.append("Einzahlung von " + input2.getText() + " erfolgreich\nNeuer Kontostand beträgt " + (bs.getKontostand(Integer.parseInt(input.getText())) / 100) + " €\n");
} catch (Exception ex) {
ex.printStackTrace();
}
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");
} catch (IOException e1) {
e1.printStackTrace();
}
}
else if (e.getSource() == button2) {
frame.dispose();
AuswahlmenüFrame amf = new AuswahlmenüFrame(bs);
}
else if (e.getSource() == button3) {
frame.dispose();
HauptmenüFrame hmf = new HauptmenüFrame(bs);
}
}
}

View File

@ -5,13 +5,12 @@ import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import de.hs_mannheim.informatik.bank.facade.Banksystem;
public class HauptmenüFrame extends JFrame implements ActionListener{
public class HauptmenüFrame implements ActionListener{
private JPanel panel;
private JFrame frame;
@ -34,6 +33,7 @@ public class HauptmenüFrame extends JFrame implements ActionListener{
frame.setSize(300, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.add(panel);
panel.setLayout(null);
@ -64,24 +64,23 @@ public class HauptmenüFrame extends JFrame implements ActionListener{
public void actionPerformed(ActionEvent e) {
System.out.println("Hauptmenü...");
boolean running = true;
while(running) {
if(e.getSource() == button) {
frame.dispose();
KundeAnlegen kundeAnlegen = new KundeAnlegen(bs);
running = false;
}
if(e.getSource() == button2) {
frame.dispose();
LoginFrame loginFrame = new LoginFrame(bs);
running = false;
}
if(e.getSource() == button) {
frame.dispose();
KundeAnlegen kundeAnlegen = new KundeAnlegen(bs);
}
else if(e.getSource() == button2) {
frame.dispose();
LoginFrame loginFrame = new LoginFrame(bs);
}
}

View File

@ -3,16 +3,16 @@ package de.hs_mannheim.informatik.bank.gui;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import de.hs_mannheim.informatik.bank.facade.Banksystem;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class KundeAnlegen extends JFrame implements ActionListener{
@ -25,8 +25,10 @@ public class KundeAnlegen extends JFrame implements ActionListener{
private JTextField input3;
private JFrame frame;
private JButton button;
private JButton button2;
private JTextArea output;
private Banksystem bs;
@ -73,11 +75,16 @@ public class KundeAnlegen extends JFrame implements ActionListener{
this.button = new JButton("Kunde anlegen");
button.addActionListener(this);
button.setBounds(120, 140, 165, 20);
button.setBounds(120, 400, 165, 20);
panel.add(button);
this.button2 = new JButton("Hauptmenü");
button2.addActionListener(this);
button2.setBounds(120, 430, 165, 20);
panel.add(button2);
this.output = new JTextArea();
output.setBounds(10, 170, 380, 290);
output.setBounds(10, 140, 365, 230);
output.setEditable(false);
panel.add(output);
@ -91,34 +98,38 @@ public class KundeAnlegen extends JFrame implements ActionListener{
public void actionPerformed(ActionEvent e) {
System.out.println("Kunde anlegen...");
boolean running = true;
String name = input.getText();
String surname = input2.getText();
int age = Integer.parseInt(input3.getText());
while(running) {
if (e.getSource() == button) {
try {
bs.setCurrentKunde(bs.addNewKunde(name, surname, age));
output.append("Ihr Kundenkonto mit der ID [" + bs.getKundenID() + "] wurde erfolgreich angelegt.\n");
bs.addNewKunde(name, surname, age);
output.append("Ihr Kundenkonto mit der ID [" + bs.getKundenID() + "] wurde erfolgreich angelegt.\n");
input.setText("");
input2.setText("");
input3.setText("");
} catch (Exception ex) {
ex.printStackTrace();
}
} else if (e.getSource() == button2) {
running = false;
frame.dispose();
HauptmenüFrame hmf = new HauptmenüFrame(bs);
}
frame.dispose();
KontoAnlegenFrame kaf = new KontoAnlegenFrame(bs);
}
}

View File

@ -0,0 +1,66 @@
package de.hs_mannheim.informatik.bank.gui;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import de.hs_mannheim.informatik.bank.facade.Banksystem;
public class LoginFehlerFrame implements ActionListener{
private JPanel panel;
private JFrame frame;
private JButton button;
private JTextArea output;
private Banksystem bs;
public LoginFehlerFrame(Banksystem bs) {
this.bs = bs;
this.panel = new JPanel();
this.frame = new JFrame();
frame.setTitle(bs.getBankname() + " - Fehlermeldung");
frame.setSize(300, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.add(panel);
panel.setLayout(null);
this.output = new JTextArea("Fehler beim Login\nKunden-ID nicht gefunden");
output.setBounds(65, 50, 150, 35);
output.setEditable(false);
panel.add(output);
this.button = new JButton("Zurück zum Login");
button.setBounds(65, 120, 150, 25);
button.addActionListener(this);
panel.add(button);
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Loginfehler...");
if(e.getSource() == button) {
frame.dispose();
LoginFrame lf = new LoginFrame(bs);
}
}
}

View File

@ -4,7 +4,6 @@ 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;
@ -12,13 +11,12 @@ import java.awt.event.ActionEvent;
import de.hs_mannheim.informatik.bank.facade.Banksystem;
public class LoginFrame extends JFrame implements ActionListener{
public class LoginFrame implements ActionListener{
private JPanel panel;
private JFrame frame;
private JButton button;
private JTextField input;
private JTextArea output;
private JLabel label;
private Banksystem bs;
@ -30,30 +28,28 @@ public class LoginFrame extends JFrame implements ActionListener{
this.panel = new JPanel();
this.frame = new JFrame();
this.frame.setTitle(bs.getBankname() + " - Login");
this.frame.setSize(400, 400);
this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.frame.add(panel);
this.panel.setLayout(null);
frame.setTitle(bs.getBankname() + " - Login");
frame.setSize(300, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.add(panel);
panel.setLayout(null);
this.label = new JLabel("Kunden-ID");
label.setBounds(10, 20, 80, 25);
this.panel.add(label);
label.setBounds(10, 17, 80, 25);
panel.add(label);
this.input = new JTextField(20);
this.input.setBounds(100, 20, 165, 25);
this.panel.add(input);
this.output = new JTextArea();
this.output.setBounds(10, 50, 300, 200);
this.panel.add(output);
input.setBounds(80, 20, 120, 20);
panel.add(input);
this.button = new JButton("Login");
this.button.setBounds(10, 300, 80, 25);
this.button.addActionListener(this);
this.panel.add(button);
button.setBounds(100, 100, 80, 25);
button.addActionListener(this);
panel.add(button);
this.frame.setVisible(true);
frame.setVisible(true);
}
@ -62,37 +58,31 @@ public class LoginFrame extends JFrame implements ActionListener{
public void actionPerformed(ActionEvent e) {
System.out.println("Login...");
boolean running = true;
int kundenID = Integer.parseInt(input.getText());
while(running){
try {
bs.setCurrentKunde(bs.getKunde(kundenID));
if(bs.getCurrentKunde() != null){
this.output.append("Login erfolgreich!");
this.frame.dispose();
frame.dispose();
AuswahlmenüFrame auswahlmenü = new AuswahlmenüFrame(bs);
running = false;
} else {
this.output.append("Login fehlgeschlagen!");
running = false;
frame.dispose();
LoginFehlerFrame lff = new LoginFehlerFrame(bs);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}