From 82f37f745bac0110aeac4009aaf36d0efb7e4fc3 Mon Sep 17 00:00:00 2001 From: Berat Date: Fri, 8 Nov 2024 20:17:53 +0100 Subject: [PATCH] final commit of the day --- PR2Bib/src/domainBib/Bibliothek.java | 23 ++++++++++++++++++++++ PR2Bib/src/guiBib/BibliothekGUI.java | 29 +++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/PR2Bib/src/domainBib/Bibliothek.java b/PR2Bib/src/domainBib/Bibliothek.java index 7e72aba..bcf03fa 100644 --- a/PR2Bib/src/domainBib/Bibliothek.java +++ b/PR2Bib/src/domainBib/Bibliothek.java @@ -1,6 +1,9 @@ package domainBib; +import java.awt.Component; import java.util.ArrayList; +import javax.swing.JLabel; + import guiBib.*; public class Bibliothek { @@ -88,4 +91,24 @@ public class Bibliothek { } return null; } + + public static int bücherLänge() { + return bücherListe.size(); + } + + public static ArrayList buchAuflisten() { + ArrayList jlabelList = new ArrayList<>(); + for(Buch b: bücherListe) { + String titel = b.getTitel(); + int jahr = b.getJahr(); + String autor = b.getAutor(); + int kennnummer = b.getKennnummer(); + JLabel buch = new JLabel("Titel: " + titel + + ", Autor: " + autor + + ", Jahr: " + jahr + + ", Kennnummer: " + kennnummer); + jlabelList.add(buch); + } + return jlabelList; + } } diff --git a/PR2Bib/src/guiBib/BibliothekGUI.java b/PR2Bib/src/guiBib/BibliothekGUI.java index afec403..6f9acb5 100644 --- a/PR2Bib/src/guiBib/BibliothekGUI.java +++ b/PR2Bib/src/guiBib/BibliothekGUI.java @@ -4,6 +4,7 @@ import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.ArrayList; public class BibliothekGUI extends JFrame implements ActionListener{ private static CardLayout cl = new CardLayout(); @@ -39,12 +40,12 @@ public class BibliothekGUI extends JFrame implements ActionListener{ bp.add(b1); bp.add(b2); loginPanel.add(bp, BorderLayout.SOUTH); - mainPanel.add(loginPanel, "loginPanel"); - cl.show(mainPanel, "loginPanel"); add(mainPanel); setVisible(true); setSize(600, 600); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + mainPanel.add(loginPanel, "loginPanel"); + cl.show(mainPanel, "loginPanel"); } public static void openAdmin() { @@ -85,7 +86,29 @@ public class BibliothekGUI extends JFrame implements ActionListener{ } private static void bookMenu() { - // TODO Auto-generated method stub + int i = Bibliothek.bücherLänge(); + if(i == 0) { + JPanel buchMenü = new JPanel(new BorderLayout()); + JLabel text1 = new JLabel("Keine Bücher mehr vorhanden"); + buchMenü.add(text1, BorderLayout.NORTH); + JButton b1 = new JButton("OK"); + buchMenü.add(b1, BorderLayout.SOUTH); + mainPanel.add(buchMenü, "Bücher"); + cl.show(mainPanel, "Bücher"); + b1.addActionListener(e -> cl.show(mainPanel, "mediumPanel")); + } + if(i != 0) { + JPanel buchMenü = new JPanel(new GridLayout(i+1, 2, 10, 10)); + ArrayList jlabelList = Bibliothek.buchAuflisten(); + for(JLabel j: jlabelList) { + buchMenü.add(j); + } + JButton b1 = new JButton("OK"); + buchMenü.add(b1, BorderLayout.SOUTH); + mainPanel.add(buchMenü, "Bücher"); + cl.show(mainPanel, "Bücher"); + b1.addActionListener(e -> cl.show(mainPanel, "mediumPanel")); + } } private static void dvdMenu() {