New: added/changed frames & code refactoring

gui
Caner 2022-11-30 23:13:15 +01:00
parent cdbd93c610
commit 0d4ec593e0
5 changed files with 288 additions and 20 deletions

View File

@ -1,10 +1,7 @@
package de.hs_mannheim.informatik.bank;
import de.hs_mannheim.informatik.bank.facade.Banksystem;
import de.hs_mannheim.informatik.bank.gui.GeldEinzahlenFrame;
import de.hs_mannheim.informatik.bank.gui.KontoAnlegenFrame;
import de.hs_mannheim.informatik.bank.gui.KontoListingFrame;
import de.hs_mannheim.informatik.bank.gui.KundeAnlegen;
import de.hs_mannheim.informatik.bank.gui.HauptmenüFrame;
public class Main {
@ -13,13 +10,7 @@ public class Main {
Banksystem bs = new Banksystem("Spaßkasse Mannheim");
KundeAnlegen ka = new KundeAnlegen(bs);
KontoAnlegenFrame kaf = new KontoAnlegenFrame(bs);
KontoListingFrame klf = new KontoListingFrame(bs);
GeldEinzahlenFrame gef = new GeldEinzahlenFrame(bs);
HauptmenüFrame hmf = new HauptmenüFrame(bs);
}

View File

@ -0,0 +1,85 @@
package de.hs_mannheim.informatik.bank.gui;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import de.hs_mannheim.informatik.bank.facade.Banksystem;
public class AuswahlmenüFrame extends JFrame implements ActionListener{
private JPanel panel;
private JFrame frame;
private JButton button;
private JButton button2;
private JButton button3;
private Banksystem bs;
public AuswahlmenüFrame(Banksystem bs){
this.bs = bs;
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);
this.button = new JButton("Konto anlegen");
this.button.setBounds(10, 80, 300, 25);
this.button.addActionListener(this);
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);
this.button3 = new JButton("Geld einzahlen");
this.button3.setBounds(10, 140, 300, 25);
this.button3.addActionListener(this);
this.panel.add(button3);
this.frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Auswahlmenü...");
boolean running = true;
while(running) {
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;
}
}
}
}

View File

@ -0,0 +1,81 @@
package de.hs_mannheim.informatik.bank.gui;
import javax.swing.JButton;
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{
private JPanel panel;
private JFrame frame;
private JButton button;
private JButton button2;
private JLabel label;
private Banksystem bs;
public HauptmenüFrame(Banksystem bs){
this.bs = bs;
this.panel = new JPanel();
this.frame = new JFrame();
this.frame.setTitle(bs.getBankname() + " - Hauptmenü");
this.frame.setSize(400, 400);
this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.frame.add(panel);
this.panel.setLayout(null);
this.label = new JLabel("Hauptmenü");
label.setBounds(10, 20, 80, 25);
this.panel.add(label);
this.button = new JButton("Bei bestehendem Kundenkonto einloggen");
this.button.setBounds(10, 80, 300, 25);
this.button.addActionListener(this);
this.panel.add(button);
this.button2 = new JButton("Neuen Kunden anlegen");
this.button2.setBounds(10, 110, 300, 25);
this.button2.addActionListener(this);
this.panel.add(button2);
this.frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Hauptmenü...");
boolean running = true;
while(running) {
if(e.getSource() == button) {
this.frame.dispose();
LoginFrame loginFrame = new LoginFrame(bs);
running = false;
}
if(e.getSource() == button2) {
this.frame.dispose();
KundeAnlegen kundeAnlegen = new KundeAnlegen(bs);
running = false;
}
}
}
}

View File

@ -87,22 +87,35 @@ 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) {
try {
bs.setCurrentKunde(bs.addNewKunde(input.getText(), input2.getText(),
Integer.parseInt(input3.getText())));
bs.setCurrentKunde(bs.addNewKunde(name, surname, age));
this.output.append("Ihr Kundenkonto mit der ID [" + bs.getKundenID() + "] wurde erfolgreich angelegt.\n");
} catch (Exception e1) {
e1.printStackTrace();
}
break;
} catch (Exception ex) {
ex.printStackTrace();
}
running = false;
}
this.frame.dispose();
KontoAnlegenFrame kaf = new KontoAnlegenFrame(bs);
}
}

View File

@ -0,0 +1,98 @@
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.awt.event.ActionEvent;
import de.hs_mannheim.informatik.bank.facade.Banksystem;
public class LoginFrame extends JFrame implements ActionListener{
private JPanel panel;
private JFrame frame;
private JButton button;
private JTextField input;
private JTextArea output;
private JLabel label;
private Banksystem bs;
public LoginFrame(Banksystem bs){
this.bs = bs;
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);
this.label = new JLabel("Kunden-ID");
label.setBounds(10, 20, 80, 25);
this.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);
this.button = new JButton("Login");
this.button.setBounds(10, 300, 80, 25);
this.button.addActionListener(this);
this.panel.add(button);
this.frame.setVisible(true);
}
@Override
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();
AuswahlmenüFrame auswahlmenü = new AuswahlmenüFrame(bs);
running = false;
} else {
this.output.append("Login fehlgeschlagen!");
running = false;
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}