diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index 1cb822e..016ba6e 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -1,13 +1,22 @@ package org.example; import org.example.framework.framecreater; +import org.example.objekts.Bibiliotek; +import org.example.objekts.kunden; import static org.example.objekts.Bibiliotek.addshit; +import static org.example.objekts.Bibiliotek.kundenliste; + public class Main { public static void main(String[] args) { //add the medien + //admin + kundenliste.add(new kunden(false,0)); addshit(); + Bibiliotek.setAngemeldeterbenuter(-1); + Bibiliotek.setFilter("Kein Filter"); + framecreater.Startframe(); } diff --git a/src/main/java/org/example/framework/framecreater.java b/src/main/java/org/example/framework/framecreater.java index 40794a5..c3bd110 100644 --- a/src/main/java/org/example/framework/framecreater.java +++ b/src/main/java/org/example/framework/framecreater.java @@ -1,15 +1,17 @@ package org.example.framework; import org.example.objekts.Bibiliotek; +import org.example.objekts.Medien; +import org.example.objekts.kunden; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.time.DateTimeException; import java.time.LocalDate; -import java.util.Date; +import java.util.ArrayList; -import static java.lang.Thread.sleep; +import static org.example.objekts.Bibiliotek.*; public class framecreater implements ActionListener { @@ -19,15 +21,24 @@ public class framecreater implements ActionListener { //frame JFrame frame=new JFrame("Bibiliotek"); JPanel panel=new JPanel(); - frame.setSize(700,700); + frame.setSize(700,900); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); frame.add(panel); panel.setLayout(null); //anmelde button --> Chanche later if user is angemeldet - JButton anemelden=new JButton("Anmelden"); - anemelden.setBounds(600,10,80,25); + JButton anemelden=new JButton(Bibiliotek.getAngemeldeterbenuter()<0 ? "Anmelden" : "Profiel"); + anemelden.setBounds(600,10,90,25); + anemelden.addActionListener(e -> { + frame.dispose(); + if(getAngemeldeterbenuter()<0){ + anmeldeframe(); + } else { + profilframe(); + } + + }); panel.add(anemelden); //date button @@ -44,6 +55,7 @@ public class framecreater implements ActionListener { filter.setBounds(10,10,80,25); filter.addActionListener(e -> { frame.dispose(); + Filterframe(); }); panel.add(filter); @@ -55,6 +67,40 @@ public class framecreater implements ActionListener { }); panel.add(Sucher); + //create blocks for the inventory + final int[] counter = {0}; + medienliste.forEach(m -> { + if(m.getClass().getName().substring(20).equals(getFilter())){ + panel.add(createbutton(m,counter[0],frame)); + counter[0]++; + } else if (getFilter().equals("Kein Filter")) { + panel.add(createbutton(m,counter[0],frame)); + counter[0]++; + } else if (getFilter().equals("Ausgeliehen") && m.getAusgeliehen()>0) { + panel.add(createbutton(m,counter[0],frame)); + counter[0]++; + } else if (getFilter().equals("Verfügbar") && m.getAusgeliehen()<=0) { + panel.add(createbutton(m,counter[0],frame)); + counter[0]++; + } + }); + + + } + + public static JButton createbutton(Medien m, int counter, JFrame frame){ + JButton vorlage=new JButton(""+m.getClass().getName().substring(20) + +"
"+m.getTitel() + +"
"+m.getBeschreibung() + +"
"+m.getVerofentlichung() + +"
"+(m.getAusgeliehen()!=0 ? "Ausgeliehen" : "Verfügbar") + +""); + vorlage.setBounds(30+(80*(counter%8)),50+(100*(counter/10)),80,100 ); + vorlage.addActionListener(e -> { + frame.dispose(); + Startframe(); + }); + return vorlage; } public static void Zeitframe(){ @@ -117,7 +163,153 @@ public class framecreater implements ActionListener { } public static void Filterframe(){ + //frame + JFrame frame=new JFrame("Filter auswählen"); + JPanel panel=new JPanel(); + ArrayList filterliste=new ArrayList<>(); + filterliste.add("Buch"); + filterliste.add("DVD"); + filterliste.add("CD"); + filterliste.add("Brettspiel"); + filterliste.add("Videospiel"); + filterliste.add("Ausgeliehen"); + filterliste.add("Verfügbar"); + filterliste.add("Kein Filter"); + frame.setSize(220,filterliste.size()*25+55); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setVisible(true); + frame.add(panel); + panel.setLayout(null); + filterliste.forEach(s -> { + //buch button + JButton buch=new JButton(s); + buch.setBounds(10,10+(25*filterliste.indexOf(s)),190,25); + buch.addActionListener(e -> { + frame.dispose(); + setFilter(s); + Startframe(); + }); + panel.add(buch); + }); + } + + public static void anmeldeframe(){ + //frame + JFrame frame=new JFrame("Anmelden"); + JPanel panel=new JPanel(); + frame.setSize(400,200); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setVisible(true); + frame.add(panel); + panel.setLayout(null); + + //text feld + JLabel text=new JLabel("Bitte gib deine Kundennummer ein:"); + text.setBounds(10,70,400,25); + panel.add(text); + + //date feld + JTextField jear=new JTextField(20); + jear.setBounds(10,100,100,25); + panel.add(jear); + + //succes button + JButton succes=new JButton("Anmelden"); + succes.setBounds(90,130,90,25); + succes.addActionListener( e -> { + try { + if(kundenliste.get(Integer.valueOf(jear.getText()))!=null){ + setAngemeldeterbenuter(Integer.valueOf(jear.getText())); + frame.dispose(); + Startframe(); + } else { + text.setText("Falsche Nummer, bitte versuche es erneut"); + } + } catch (NumberFormatException ec){ + text.setText("Falsche Nummer, bitte versuche es erneut"); + } catch (IndexOutOfBoundsException ec){ + text.setText("Falsche Nummer, bitte versuche es erneut"); + } + }); + panel.add(succes); + + //regestrieren button + JButton regestrieren=new JButton("Registrieren"); + regestrieren.setBounds(180,130,80,25); + regestrieren.addActionListener( e -> { + kundenliste.add(new kunden(false,(kundenliste.size()))); + setAngemeldeterbenuter(kundenliste.size()-1); + frame.dispose(); + Startframe(); + }); + panel.add(regestrieren); + + //back button + JButton back=new JButton("Zurück"); + back.setBounds(10,130,80,25); + back.addActionListener(e -> { + frame.dispose(); + Startframe(); + }); + panel.add(back); + } + + public static void profilframe(){ + //frame + JFrame frame=new JFrame("Profil"); + JPanel panel=new JPanel(); + frame.setSize(400,800); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setVisible(true); + frame.add(panel); + panel.setLayout(null); + + kunden k=kundenliste.get(getAngemeldeterbenuter()); + + //text feld + JLabel nummer=new JLabel("Kunden Nummer: "+(k.getnummer())); + nummer.setBounds(10,10,200,25); + panel.add(nummer); + + //text feld + JLabel schulden=new JLabel("Schulden: "+k.getSchulden()); + schulden.setBounds( 10,30,200,25); + panel.add(schulden); + + //studentstatus feld + JLabel studentstatus=new JLabel("Student/Schühler: "+( k.isIstStudent()? "Ja" : "Nein")); + studentstatus.setBounds(10,50,200,25); + panel.add(studentstatus); + + //studentstatus button + JButton succes=new JButton("Ändern"); + succes.setBounds(170,50,80,25); + succes.addActionListener( e -> { + frame.dispose(); + k.setIstStudent(!k.isIstStudent()); + profilframe(); + }); + panel.add(succes); + + //back button + JButton back=new JButton("Zurück"); + back.setBounds(10,725,80,25); + back.addActionListener(e -> { + frame.dispose(); + Startframe(); + }); + panel.add(back); + + //back button + JButton abmelden=new JButton("Abmelden"); + abmelden.setBounds(90,725,100,25); + abmelden.addActionListener(e -> { + frame.dispose(); + setAngemeldeterbenuter(-1); + Startframe(); + }); + panel.add(abmelden); } @Override diff --git a/src/main/java/org/example/objekts/Bibiliotek.java b/src/main/java/org/example/objekts/Bibiliotek.java index 087d7f4..5d5517b 100644 --- a/src/main/java/org/example/objekts/Bibiliotek.java +++ b/src/main/java/org/example/objekts/Bibiliotek.java @@ -9,6 +9,11 @@ public class Bibiliotek { public static ArrayList medienliste=new ArrayList<>(); public static ArrayList kundenliste=new ArrayList<>(); + private static int Angemeldeterbenuter; + + private static String Filter; + + // Global system date, initialized to the current date private static LocalDate datum = LocalDate.now(); @@ -22,9 +27,43 @@ public class Bibiliotek { datum = newDate; } + public static int getAngemeldeterbenuter() { + return Angemeldeterbenuter; + } + + public static void setAngemeldeterbenuter(int angemeldeterbenuter) { + Angemeldeterbenuter = angemeldeterbenuter; + } + + public static String getFilter() { + return Filter; + } + + public static void setFilter(String filter) { + Filter = filter; + } + public static void addshit(){ medienliste.add(new Buch("Schmi","","",1)); - for (Medien m : medienliste) if(m instanceof Buch) System.out.println(true); - + medienliste.add(new DVD("Schmi2","","s",1)); + medienliste.add(new Buch("Schmi3","","s",1)); + medienliste.add(new Buch("Schmi4","","",1)); + medienliste.add(new Buch("Schmi5","","",1)); + medienliste.add(new Buch("Schmi6","","as",1)); + medienliste.add(new Buch("Schmi6","","as",1)); + medienliste.add(new Buch("Schmi6","","as",1)); + medienliste.add(new DVD("Schmi6","","as",1)); + medienliste.add(new Buch("Schmi6","","as",1)); + medienliste.add(new Buch("Schmi6","","as",1)); + medienliste.add(new Buch("Schmi6","","as",1)); + medienliste.add(new Buch("Schmi6","","as",1)); + medienliste.add(new Buch("Schmi6","","as",1)); + medienliste.add(new Buch("Schmi6","","as",1)); + medienliste.add(new Buch("Schmi6","","as",1)); + medienliste.add(new DVD("Schmi6","","as",1)); + medienliste.add(new Buch("Schmi6","","as",1)); + medienliste.add(new Buch("Schmi6","","as",1)); + medienliste.add(new Buch("Schmi6","","as",1)); + medienliste.add(new Buch("Schmi6","","as",1)); } } diff --git a/src/main/java/org/example/objekts/kunden.java b/src/main/java/org/example/objekts/kunden.java index b7a4cdf..bc28f62 100644 --- a/src/main/java/org/example/objekts/kunden.java +++ b/src/main/java/org/example/objekts/kunden.java @@ -1,6 +1,5 @@ package org.example.objekts; -import java.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -41,4 +40,8 @@ public class kunden { public void setAusgeliehen(HashMap ausgeliehen) { this.ausgeliehen = ausgeliehen; } + + public void setIstStudent(boolean istStudent) { + this.istStudent = istStudent; + } } diff --git a/target/classes/org/example/Main.class b/target/classes/org/example/Main.class index 4e75da4..57950d5 100644 Binary files a/target/classes/org/example/Main.class and b/target/classes/org/example/Main.class differ diff --git a/target/classes/org/example/framework/framecreater.class b/target/classes/org/example/framework/framecreater.class index 3d20292..2b04a7a 100644 Binary files a/target/classes/org/example/framework/framecreater.class and b/target/classes/org/example/framework/framecreater.class differ diff --git a/target/classes/org/example/objekts/Bibiliotek.class b/target/classes/org/example/objekts/Bibiliotek.class index ceb7f49..190ace4 100644 Binary files a/target/classes/org/example/objekts/Bibiliotek.class and b/target/classes/org/example/objekts/Bibiliotek.class differ diff --git a/target/classes/org/example/objekts/kunden.class b/target/classes/org/example/objekts/kunden.class new file mode 100644 index 0000000..a696003 Binary files /dev/null and b/target/classes/org/example/objekts/kunden.class differ