From cdbd93c6104ca8a2d4e603b8b478105645bfc1aa Mon Sep 17 00:00:00 2001 From: Caner Date: Wed, 30 Nov 2022 15:36:01 +0100 Subject: [PATCH] New: added/changed frames --- .../de/hs_mannheim/informatik/bank/Main.java | 11 ++- .../bank/gui/GeldEinzahlenFrame.java | 93 +++++++++++++++++++ .../bank/gui/KontoAnlegenFrame.java | 85 +++++++++++------ .../bank/gui/KontoListingFrame.java | 52 ++++++----- .../informatik/bank/gui/KundeAnlegen.java | 4 +- 5 files changed, 189 insertions(+), 56 deletions(-) create mode 100644 Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/GeldEinzahlenFrame.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 cbb8f5c..a73fdd5 100644 --- a/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/Main.java +++ b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/Main.java @@ -1,7 +1,9 @@ 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; @@ -11,8 +13,13 @@ public class Main { Banksystem bs = new Banksystem("Spaßkasse Mannheim"); - KundeAnlegen tp = new KundeAnlegen(bs); + KundeAnlegen ka = new KundeAnlegen(bs); + + KontoAnlegenFrame kaf = new KontoAnlegenFrame(bs); + KontoListingFrame klf = new KontoListingFrame(bs); + + GeldEinzahlenFrame gef = new GeldEinzahlenFrame(bs); } diff --git a/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/GeldEinzahlenFrame.java b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/GeldEinzahlenFrame.java new file mode 100644 index 0000000..f0fb5ef --- /dev/null +++ b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/GeldEinzahlenFrame.java @@ -0,0 +1,93 @@ +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 GeldEinzahlenFrame extends JFrame implements ActionListener { + + private JPanel panel; + private JFrame frame; + private JLabel label; + private JLabel label2; + private JTextField input; + private JTextField input2; + private JTextArea output; + private JButton button; + + private Banksystem bs; + + public GeldEinzahlenFrame(Banksystem bs){ + + this.bs = bs; + + 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); + + this.label = new JLabel("Kontonummer"); + 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.label2 = new JLabel("Betrag"); + label2.setBounds(10, 50, 80, 25); + this.panel.add(label2); + + this.input2 = new JTextField(20); + this.input2.setBounds(100, 50, 165, 25); + this.panel.add(input2); + + this.output = new JTextArea(); + this.output.setBounds(10, 110, 300, 200); + this.output.setEditable(false); + this.panel.add(output); + + this.button = new JButton("Einzahlen"); + button.addActionListener(this); + button.setBounds(10, 320, 300, 25); + this.panel.add(button); + + this.frame.setVisible(true); + + } + + + @Override + public void actionPerformed(ActionEvent e) { + + System.out.println("Geld einzahlen..."); + 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(); + } + + + + } + + + +} diff --git a/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/KontoAnlegenFrame.java b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/KontoAnlegenFrame.java index 9357ae4..eb3b723 100644 --- a/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/KontoAnlegenFrame.java +++ b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/KontoAnlegenFrame.java @@ -5,18 +5,23 @@ import java.awt.event.ActionEvent; import javax.swing.JButton; import javax.swing.JFrame; -import javax.swing.JScrollPane; +import javax.swing.JPanel; import javax.swing.JTextArea; -import javax.swing.JTextField; + import de.hs_mannheim.informatik.bank.domain.Kontoart; import de.hs_mannheim.informatik.bank.facade.Banksystem; public class KontoAnlegenFrame extends JFrame implements ActionListener { - private JTextField eingabe; - private JTextArea ausgabe; - private JButton ok; + private JPanel panel; + private JFrame frame; + private JButton button; + private JButton button2; + private JButton button3; + private JTextArea output; + + private Banksystem bs; @@ -24,24 +29,35 @@ public class KontoAnlegenFrame extends JFrame implements ActionListener { this.bs = bs; - this.setTitle(bs.getBankname()); - this.setSize(400, 300); - this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + this.panel = new JPanel(); - eingabe = new JTextField(20); + 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); - ausgabe = new JTextArea(10, 20); - ausgabe.setLineWrap(true); - ausgabe.setWrapStyleWord(true); + this.button = new JButton("Girokonto"); + this.button.setBounds(10, 80, 80, 25); + this.button.addActionListener(this); + this.panel.add(button); - JScrollPane sp = new JScrollPane(ausgabe); + this.button2 = new JButton("Sparkonto"); + this.button2.setBounds(100, 80, 80, 25); + this.button2.addActionListener(this); + this.panel.add(button2); - ok = new JButton("Konto anlegen"); - ok.addActionListener(this); + this.button3 = new JButton("Depot"); + this.button3.setBounds(190, 80, 80, 25); + this.button3.addActionListener(this); + this.panel.add(button3); - this.add(eingabe, "North"); - this.add(sp, "Center"); - this.add(ok, "South"); + this.output = new JTextArea(20, 20); + this.output.setBounds(10, 110, 300, 200); + this.output.setEditable(false); + this.panel.add(output); + + this.frame.setVisible(true); } @@ -49,19 +65,36 @@ public class KontoAnlegenFrame extends JFrame implements ActionListener { public void actionPerformed(ActionEvent e) { System.out.println("Konto anlegen..."); + boolean running = true; - try { + while(running) { - int knr = bs.kontoAnlegen(bs.getCurrentKunde(), Kontoart.Sparkonto); + try { - this.ausgabe.append("Neus Konto angelegt: " + knr + "\n"); - } catch (Exception e1) { - - e1.printStackTrace(); + 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; + } + + } + catch (Exception ex) { + ex.printStackTrace(); + } + + running = false; + } - - + } diff --git a/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/KontoListingFrame.java b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/KontoListingFrame.java index a9b72fc..23869f9 100644 --- a/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/KontoListingFrame.java +++ b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/gui/KontoListingFrame.java @@ -5,17 +5,19 @@ import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; -import javax.swing.JScrollPane; +import javax.swing.JPanel; import javax.swing.JTextArea; -import javax.swing.JTextField; + import de.hs_mannheim.informatik.bank.facade.Banksystem; public class KontoListingFrame extends JFrame implements ActionListener{ - private JTextField eingabe; - private JTextArea ausgabe; - private JButton ok; + private JPanel panel; + private JFrame frame; + private JButton button; + private JTextArea output; + private Banksystem bs; @@ -23,24 +25,26 @@ public class KontoListingFrame extends JFrame implements ActionListener{ this.bs = bs; - this.setTitle(bs.getBankname()); - this.setSize(300, 300); - this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + 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); - eingabe = new JTextField(20); + this.button = new JButton("Kontoliste abrufen"); + this.button.setBounds(10, 80, 160, 25); + this.button.addActionListener(this); + this.panel.add(button); - ausgabe = new JTextArea(5, 20); - ausgabe.setLineWrap(true); - ausgabe.setWrapStyleWord(true); + this.output = new JTextArea(20, 20); + this.output.setBounds(10, 110, 300, 200); + this.output.setEditable(false); + this.panel.add(output); - JScrollPane sp = new JScrollPane(ausgabe); - - ok = new JButton("Kontenliste abrufen"); - ok.addActionListener(this); - - this.add(eingabe, "North"); - this.add(sp, "Center"); - this.add(ok, "South"); + + this.frame.setVisible(true); } @@ -48,13 +52,11 @@ public class KontoListingFrame extends JFrame implements ActionListener{ public void actionPerformed(ActionEvent e) { System.out.println("Kontenliste abrufen..."); - ausgabe.setText(""); String[] konten = bs.getKontenlisteForKunde(); - - for (String konto : konten) { - ausgabe.append(konto + "\n"); - } + for(String konto : konten){ + this.output.append(konto + "\n"); + } } } 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 afd0735..25cee91 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 @@ -38,7 +38,7 @@ public class KundeAnlegen extends JFrame implements ActionListener{ this.frame = new JFrame(); - this.frame.setTitle(bs.getBankname()); + this.frame.setTitle(bs.getBankname() + " - Kunde anlegen"); this.frame.setSize(400, 400); this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.frame.add(panel); @@ -70,8 +70,6 @@ public class KundeAnlegen extends JFrame implements ActionListener{ this.output = new JTextArea(10, 20); this.output.setBounds(10, 110, 300, 200); - this.output.setLineWrap(true); - this.output.setWrapStyleWord(true); this.output.setEditable(false); this.panel.add(output);