From 560dca71101b297cf60ebf2d44e07d675bf764dd Mon Sep 17 00:00:00 2001 From: 3010293 <3010293@stud.hs-mannheim.de> Date: Sun, 10 Nov 2024 19:06:24 +0100 Subject: [PATCH] added register new user feature --- PR2Bib/src/domainBib/Bibliothek.java | 16 ++++++++++++++++ PR2Bib/src/guiBib/BibliothekGUI.java | 24 ++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/PR2Bib/src/domainBib/Bibliothek.java b/PR2Bib/src/domainBib/Bibliothek.java index 1a685c4..5ae8813 100644 --- a/PR2Bib/src/domainBib/Bibliothek.java +++ b/PR2Bib/src/domainBib/Bibliothek.java @@ -510,6 +510,22 @@ public class Bibliothek { } return jlabelList; } + + public static int getNewKennnummer() { + int newKennnummer = 0; + for(Kunde k: kundenListe) { + int nummer = k.getKennnummer(); + if(nummer > newKennnummer) { + newKennnummer = nummer; + } + } + newKennnummer += 1; + return newKennnummer; + } + + public static void addCustomer(Kunde k) { + kundenListe.add(k); + } } diff --git a/PR2Bib/src/guiBib/BibliothekGUI.java b/PR2Bib/src/guiBib/BibliothekGUI.java index e7d8774..c2e8055 100644 --- a/PR2Bib/src/guiBib/BibliothekGUI.java +++ b/PR2Bib/src/guiBib/BibliothekGUI.java @@ -86,8 +86,28 @@ public class BibliothekGUI extends JFrame implements ActionListener{ } private void nutzerAnlegen() { - // TODO Auto-generated method stub - + JPanel registerMenu = new JPanel(new BorderLayout()); + int newKennnummer = Bibliothek.getNewKennnummer(); + JLabel text0 = new JLabel("Ihre Kennnummmer wird " + newKennnummer + " sein."); + JCheckBox studentOrNot = new JCheckBox("Sind Sie Student? Falls ja bitte anklicken."); + registerMenu.add(text0, BorderLayout.NORTH); + registerMenu.add(studentOrNot, BorderLayout.CENTER); + final boolean[] isStudent = {false}; + studentOrNot.addActionListener(e -> isStudent[0] = studentOrNot.isSelected()); + JPanel bg = new JPanel(new GridLayout(1,2,10,10)); + JButton b2 = new JButton("OK"); + b2.addActionListener(e -> { + Kunde k = new Kunde(isStudent[0], newKennnummer); + Bibliothek.addCustomer(k); + cl.show(mainPanel, "loginPanel"); + }); + JButton b1 = new JButton("Abbrechen"); + b1.addActionListener(e -> cl.show(mainPanel, "loginPanel")); + bg.add(b1); + bg.add(b2); + registerMenu.add(bg, BorderLayout.SOUTH); + mainPanel.add(registerMenu, "registerMenu"); + cl.show(mainPanel, "registerMenu"); } private static void openAdmin() {