From 0d4ec593e080944923bb40b07c953a389ce96f02 Mon Sep 17 00:00:00 2001 From: Caner Date: Wed, 30 Nov 2022 23:13:15 +0100 Subject: [PATCH] New: added/changed frames & code refactoring --- .../de/hs_mannheim/informatik/bank/Main.java | 13 +-- .../informatik/bank/gui/AuswahlmenüFrame.java | 85 ++++++++++++++++ .../informatik/bank/gui/HauptmenüFrame.java | 81 +++++++++++++++ .../informatik/bank/gui/KundeAnlegen.java | 31 ++++-- .../informatik/bank/gui/LoginFrame.java | 98 +++++++++++++++++++ 5 files changed, 288 insertions(+), 20 deletions(-) create mode 100644 Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/AuswahlmenüFrame.java create mode 100644 Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/HauptmenüFrame.java create mode 100644 Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/LoginFrame.java diff --git a/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/Main.java b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/Main.java index a73fdd5..07dfcba 100644 --- a/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/Main.java +++ b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/Main.java @@ -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); } diff --git a/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/AuswahlmenüFrame.java b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/AuswahlmenüFrame.java new file mode 100644 index 0000000..b2cb585 --- /dev/null +++ b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/AuswahlmenüFrame.java @@ -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; + } + + } + + + } + + +} diff --git a/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/HauptmenüFrame.java b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/HauptmenüFrame.java new file mode 100644 index 0000000..2b541f2 --- /dev/null +++ b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/HauptmenüFrame.java @@ -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; + } + + } + + + } + +} diff --git a/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/KundeAnlegen.java b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/KundeAnlegen.java index 25cee91..dff81ad 100644 --- a/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/KundeAnlegen.java +++ b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/KundeAnlegen.java @@ -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()); - try { + while(running) { - bs.setCurrentKunde(bs.addNewKunde(input.getText(), input2.getText(), - Integer.parseInt(input3.getText()))); + try { - this.output.append("Ihr Kundenkonto mit der ID [" + bs.getKundenID() + "] wurde erfolgreich angelegt.\n"); + bs.setCurrentKunde(bs.addNewKunde(name, surname, age)); + + this.output.append("Ihr Kundenkonto mit der ID [" + bs.getKundenID() + "] wurde erfolgreich angelegt.\n"); + + break; + + } catch (Exception ex) { + ex.printStackTrace(); + } + + + running = false; - } catch (Exception e1) { - e1.printStackTrace(); } + this.frame.dispose(); + KontoAnlegenFrame kaf = new KontoAnlegenFrame(bs); + + } - - - } diff --git a/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/LoginFrame.java b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/LoginFrame.java new file mode 100644 index 0000000..b33c6c0 --- /dev/null +++ b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/LoginFrame.java @@ -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(); + } + + + + } + + + + } + +}