From b11b2ae858b36f237cbdd74708fd1c704f1bfae8 Mon Sep 17 00:00:00 2001 From: Berat Kocak <3010293@stud.hs-mannheim.de> Date: Mon, 18 Nov 2024 10:27:14 +0100 Subject: [PATCH] PR2Bib/src/guiBib/BibliothekGUI.java aktualisiert --- PR2Bib/src/guiBib/BibliothekGUI.java | 69 +++++++++++++--------------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/PR2Bib/src/guiBib/BibliothekGUI.java b/PR2Bib/src/guiBib/BibliothekGUI.java index 9fdd70e..78baf36 100644 --- a/PR2Bib/src/guiBib/BibliothekGUI.java +++ b/PR2Bib/src/guiBib/BibliothekGUI.java @@ -344,57 +344,30 @@ public class BibliothekGUI extends JFrame implements ActionListener{ private static void searchMenu(Kunde k) { JPanel mainSearch = new JPanel(new BorderLayout()); //NORTH: Search bar - JPanel enterSearch = new JPanel(new GridLayout(1,4,10,10)); + JPanel enterSearch = new JPanel(new GridLayout(1,3,10,10)); JLabel text0 = new JLabel("Geben Sie einen Suchbegriff ein:"); JTextField enterSearchTerm = new JTextField(20); - JButton b0 = new JButton("Suchen"); + //Hilfe von ChatGPT, da ich nicht wusste wie ich eine Checkbox hinzufüge und abhöre, ob + //sie gedrückt ist oder nicht box0.isSelected();) JCheckBox box0 = new JCheckBox("Nur ausleihbare Medien anzeigen"); enterSearch.add(text0); enterSearch.add(enterSearchTerm); - enterSearch.add(b0); enterSearch.add(box0); mainSearch.add(enterSearch, BorderLayout.NORTH); //CENTER: Matched media mainSearch.revalidate(); int[] doThis = {0}; box0.addActionListener(e -> { - if(box0.isSelected()) { - doThis[0] = 0; - } else { - doThis[0] = 1; - } - }); - if(doThis[0] == 0) { - b0.addActionListener(e -> { - String searchTerm = enterSearchTerm.getText().toString(); - ArrayList matchedMedia = Bibliothek.findMatchesFiltered(searchTerm); - int i = matchedMedia.size(); - if(i == 0) { - JLabel text1 = new JLabel("Nichts passendes zu dem Suchbegriff " + searchTerm + " gefunden."); - mainSearch.revalidate(); - mainSearch.add(text1, BorderLayout.CENTER); - mainSearch.revalidate(); - } else if (i > 0){ - JPanel ergebnisPanel = new JPanel(new GridLayout(i, 1, 10,10)); - for(JLabel j: matchedMedia) { - ergebnisPanel.add(j); - } - mainSearch.revalidate(); - mainSearch.add(ergebnisPanel, BorderLayout.CENTER); - mainSearch.revalidate(); - } - }); - } - if(doThis[0] == 1) { - b0.addActionListener(e -> { + if(box0.isSelected() == true) { String searchTerm = enterSearchTerm.getText().toString(); - ArrayList matchedMedia = Bibliothek.findMatchesUnfiltered(searchTerm); + ArrayList matchedMedia = Bibliothek.findMatchesFiltered(searchTerm); int i = matchedMedia.size(); if(i == 0) { JLabel text1 = new JLabel("Nichts passendes zu dem Suchbegriff " + searchTerm + " gefunden."); mainSearch.revalidate(); mainSearch.add(text1, BorderLayout.CENTER); mainSearch.revalidate(); + System.out.println("UNFIL"); } else if (i > 0){ JPanel ergebnisPanel = new JPanel(new GridLayout(i, 1, 10,10)); for(JLabel j: matchedMedia) { @@ -405,8 +378,32 @@ public class BibliothekGUI extends JFrame implements ActionListener{ mainSearch.revalidate(); } mainSearch.revalidate(); - }); - } + doThis[0] = 0; + } + else if(box0.isSelected() == false){ + String searchTerm = enterSearchTerm.getText().toString(); + ArrayList matchedMedia = Bibliothek.findMatchesUnfiltered(searchTerm); + int i = matchedMedia.size(); + if(i == 0) { + JLabel text1 = new JLabel("Nichts passendes zu dem Suchbegriff " + searchTerm + " gefunden."); + mainSearch.revalidate(); + mainSearch.add(text1, BorderLayout.CENTER); + mainSearch.revalidate(); + System.out.println("FIL"); + } else if (i > 0){ + JPanel ergebnisPanel = new JPanel(new GridLayout(i, 1, 10,10)); + for(JLabel j: matchedMedia) { + ergebnisPanel.add(j); + } + mainSearch.revalidate(); + mainSearch.add(ergebnisPanel, BorderLayout.CENTER); + mainSearch.revalidate(); + } + mainSearch.revalidate(); + doThis[0] = 0; + } + }); + mainSearch.revalidate(); //SOUTH: OK Button to return JButton b1 = new JButton("OK"); b1.addActionListener(e -> cl.show(mainPanel, "suchenMenu")); @@ -415,7 +412,7 @@ public class BibliothekGUI extends JFrame implements ActionListener{ mainPanel.add(mainSearch, "Stichwort"); cl.show(mainPanel, "Stichwort"); } - + private static void verlängern(Kunde k, String datumArray) { JPanel verlängerungPanel = new JPanel(new BorderLayout());