265 lines
8.8 KiB
Java
265 lines
8.8 KiB
Java
package guiBib;
|
|
import domainBib.*;
|
|
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();
|
|
private static JPanel mainPanel = new JPanel(cl);
|
|
|
|
public static void main(String[] args) {
|
|
SwingUtilities.invokeLater(BibliothekGUI::new);
|
|
}
|
|
|
|
|
|
public BibliothekGUI() {
|
|
Bibliothek.makeEntries();
|
|
JPanel loginPanel = new JPanel(new BorderLayout());
|
|
JLabel text1 = new JLabel("Login mit Kennnummer:");
|
|
loginPanel.add(text1, BorderLayout.NORTH);
|
|
JTextField field1 = new JTextField(20);
|
|
loginPanel.add(field1, BorderLayout.CENTER);
|
|
JPanel bp = new JPanel(new GridLayout(1,2,10,10));
|
|
JButton b1 = new JButton("Abbrechen");
|
|
b1.addActionListener(e -> dispose());
|
|
JButton b2 = new JButton("OK");
|
|
b2.addActionListener(e -> {
|
|
String loginStr = field1.getText();
|
|
Integer login = Integer.parseInt(loginStr);
|
|
if(login == 1) {openAdmin();}else {
|
|
Kunde k = Bibliothek.validateLogin(login);
|
|
String text = k.getClass().toString();
|
|
int lastDotIndex = text.lastIndexOf(".");
|
|
String substring = text.substring(lastDotIndex + 1);
|
|
if(substring.equals("Kunde")) {openMainMenu(k);}
|
|
}});
|
|
bp.add(b1);
|
|
bp.add(b2);
|
|
loginPanel.add(bp, BorderLayout.SOUTH);
|
|
add(mainPanel);
|
|
setVisible(true);
|
|
setSize(600, 600);
|
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
mainPanel.add(loginPanel, "loginPanel");
|
|
cl.show(mainPanel, "loginPanel");
|
|
}
|
|
|
|
public static void openAdmin() {
|
|
JPanel adminPanel = new JPanel(new BorderLayout());
|
|
JPanel adminGrid = new JPanel(new GridLayout(2, 1, 10, 10));
|
|
JLabel text1 = new JLabel("Admin-Bildschirm");
|
|
adminPanel.add(text1, BorderLayout.NORTH);
|
|
JButton b0 = new JButton("Ausloggen");
|
|
b0.addActionListener(e -> cl.show(mainPanel, "loginPanel"));
|
|
adminPanel.add(b0, BorderLayout.SOUTH);
|
|
JButton b1 = new JButton("Liste aller Kunden ansehen");
|
|
b1.addActionListener(e -> userListMenu());
|
|
JButton b2 = new JButton("Gebühren überschreiben");
|
|
b2.addActionListener(e -> userOwedMenu());
|
|
adminGrid.add(b1);
|
|
adminGrid.add(b2);
|
|
adminPanel.add(adminGrid, BorderLayout.CENTER);
|
|
mainPanel.add(adminPanel, "adminMenu");
|
|
cl.show(mainPanel, "adminMenu");
|
|
}
|
|
|
|
private static void userListMenu() {
|
|
int i = Bibliothek.getUserListLength();
|
|
JPanel userListPanel = new JPanel(new GridLayout(i+1, 2, 10, 10));
|
|
ArrayList<JLabel> jlabelList = Bibliothek.nutzerAuflisten();
|
|
for(JLabel j: jlabelList) {
|
|
userListPanel.add(j);
|
|
}
|
|
JButton b1 = new JButton("OK");
|
|
b1.addActionListener(e -> cl.show(mainPanel, "adminMenu"));
|
|
userListPanel.add(b1, BorderLayout.SOUTH);
|
|
mainPanel.add(userListPanel, "userList");
|
|
cl.show(mainPanel, "userList");
|
|
}
|
|
|
|
|
|
private static void userOwedMenu() {
|
|
|
|
}
|
|
|
|
|
|
public static void openMainMenu(Kunde k) {
|
|
JPanel mediumPanel = new JPanel(new GridLayout(10, 1, 10, 10));
|
|
JLabel text1 = new JLabel("Ihre Kennnnummer: " + k.getKennnummer());
|
|
mediumPanel.add(text1);
|
|
JButton b1 = new JButton("Bücher");
|
|
b1.addActionListener(e -> bookMenu());
|
|
JButton b2 = new JButton("DVDs");
|
|
b2.addActionListener(e -> dvdMenu());
|
|
JButton b3 = new JButton("CDs");
|
|
b3.addActionListener(e -> cdMenu());
|
|
JButton b4 = new JButton("Brettspiele");
|
|
b4.addActionListener(e -> bsMenu());
|
|
JButton b5 = new JButton("Videospiele");
|
|
b5.addActionListener(e -> vsMenu());
|
|
JButton b6 = new JButton("Aushleihe");
|
|
b6.addActionListener(e -> ausleihenMenü(k));
|
|
JButton b7 = new JButton("Rückgabe");
|
|
b7.addActionListener(e -> rückgabeMenü(k));
|
|
JButton b8 = new JButton("Meine Ausgeliehenen Medien");
|
|
b8.addActionListener(e -> myBooks(k));
|
|
JButton b9 = new JButton("Ausloggen");
|
|
b9.addActionListener(e -> cl.show(mainPanel, "loginPanel"));
|
|
mediumPanel.add(b1);
|
|
mediumPanel.add(b2);
|
|
mediumPanel.add(b3);
|
|
mediumPanel.add(b4);
|
|
mediumPanel.add(b5);
|
|
mediumPanel.add(b6);
|
|
mediumPanel.add(b7);
|
|
mediumPanel.add(b8);
|
|
mediumPanel.add(b9);
|
|
mainPanel.add(mediumPanel, "mediumPanel");
|
|
cl.show(mainPanel, "mediumPanel");
|
|
}
|
|
|
|
private static void ausleihenMenü(Kunde k) {
|
|
JPanel ausleihMenü = new JPanel(new BorderLayout());
|
|
JLabel text1 = new JLabel("Zu ausleihende Kennnummer des Mediums eingeben:");
|
|
JTextField inputField = new JTextField(20);
|
|
ausleihMenü.add(text1, BorderLayout.NORTH);
|
|
ausleihMenü.add(inputField, BorderLayout.CENTER);
|
|
JPanel buttonGrid = new JPanel(new GridLayout(2, 1, 10,10));
|
|
JButton b1 = new JButton("Abbrechen");
|
|
b1.addActionListener(e -> cl.show(mainPanel, "mediumPanel"));
|
|
JButton b2 = new JButton("OK");
|
|
b2.addActionListener(e -> {
|
|
int kennnummer = Integer.parseInt(inputField.getText());
|
|
Bibliothek.ausleihe(kennnummer, k);
|
|
cl.show(mainPanel, "mediumPanel");
|
|
});
|
|
buttonGrid.add(b1);
|
|
buttonGrid.add(b2);
|
|
ausleihMenü.add(buttonGrid, BorderLayout.SOUTH);
|
|
mainPanel.add(ausleihMenü, "Ausleihen");
|
|
cl.show(mainPanel, "Ausleihen");
|
|
}
|
|
|
|
private static void rückgabeMenü(Kunde k) {
|
|
JPanel rückgabeMenü = new JPanel(new BorderLayout());
|
|
JLabel text1 = new JLabel("Kennnummer des Mediums zur Rückgabe eingeben:");
|
|
JTextField inputField = new JTextField(20);
|
|
rückgabeMenü.add(text1, BorderLayout.NORTH);
|
|
rückgabeMenü.add(inputField, BorderLayout.CENTER);
|
|
JPanel buttonGrid = new JPanel(new GridLayout(2, 1, 10,10));
|
|
JButton b1 = new JButton("Abbrechen");
|
|
b1.addActionListener(e -> cl.show(mainPanel, "mediumPanel"));
|
|
JButton b2 = new JButton("OK");
|
|
b2.addActionListener(e -> {
|
|
int kennnummer = Integer.parseInt(inputField.getText());
|
|
Bibliothek.rückgabe(kennnummer, k);
|
|
myBooks(k);
|
|
});
|
|
buttonGrid.add(b1);
|
|
buttonGrid.add(b2);
|
|
rückgabeMenü.add(buttonGrid, BorderLayout.SOUTH);
|
|
mainPanel.add(rückgabeMenü, "Rückgabe");
|
|
cl.show(mainPanel, "Rückgabe");
|
|
}
|
|
|
|
private static void bookMenu() {
|
|
int i = Bibliothek.bücherLänge();
|
|
JPanel buchMenü = new JPanel(new GridLayout(i+1, 2, 10, 10));
|
|
ArrayList<JLabel> jlabelList = Bibliothek.buchAuflisten();
|
|
for(JLabel j: jlabelList) {
|
|
buchMenü.add(j);
|
|
}
|
|
JButton b1 = new JButton("OK");
|
|
b1.addActionListener(e -> cl.show(mainPanel, "mediumPanel"));
|
|
buchMenü.add(b1, BorderLayout.SOUTH);
|
|
mainPanel.add(buchMenü, "Bücher");
|
|
cl.show(mainPanel, "Bücher");
|
|
}
|
|
|
|
private static void dvdMenu() {
|
|
int i = Bibliothek.dvdLänge();
|
|
JPanel dvdMenü = new JPanel(new GridLayout(i+1, 2, 10, 10));
|
|
ArrayList<JLabel> jlabelList = Bibliothek.dvdAuflisten();
|
|
for(JLabel j: jlabelList) {
|
|
dvdMenü.add(j);
|
|
}
|
|
JButton b1 = new JButton("OK");
|
|
b1.addActionListener(e -> cl.show(mainPanel, "mediumPanel"));
|
|
dvdMenü.add(b1, BorderLayout.SOUTH);
|
|
mainPanel.add(dvdMenü, "DVDs");
|
|
cl.show(mainPanel, "DVDs");
|
|
}
|
|
|
|
private static void cdMenu() {
|
|
int i = Bibliothek.cdLänge();
|
|
JPanel cdMenü = new JPanel(new GridLayout(i+1, 2, 10, 10));
|
|
ArrayList<JLabel> jlabelList = Bibliothek.cdAuflisten();
|
|
for(JLabel j: jlabelList) {
|
|
cdMenü.add(j);
|
|
}
|
|
JButton b1 = new JButton("OK");
|
|
b1.addActionListener(e -> cl.show(mainPanel, "mediumPanel"));
|
|
cdMenü.add(b1, BorderLayout.SOUTH);
|
|
mainPanel.add(cdMenü, "CDs");
|
|
cl.show(mainPanel, "CDs");
|
|
}
|
|
|
|
private static void bsMenu() {
|
|
int i = Bibliothek.bsLänge();
|
|
JPanel bsMenü = new JPanel(new GridLayout(i+1, 2, 10, 10));
|
|
ArrayList<JLabel> jlabelList = Bibliothek.bsAuflisten();
|
|
for(JLabel j: jlabelList) {
|
|
bsMenü.add(j);
|
|
}
|
|
JButton b1 = new JButton("OK");
|
|
b1.addActionListener(e -> cl.show(mainPanel, "mediumPanel"));
|
|
bsMenü.add(b1, BorderLayout.SOUTH);
|
|
mainPanel.add(bsMenü, "Brettspiele");
|
|
cl.show(mainPanel, "Brettspiele");
|
|
}
|
|
|
|
|
|
private static void vsMenu() {
|
|
int i = Bibliothek.vsLänge();
|
|
JPanel vsMenü = new JPanel(new GridLayout(i+1, 2, 10, 10));
|
|
ArrayList<JLabel> jlabelList = Bibliothek.vsAuflisten();
|
|
for(JLabel j: jlabelList) {
|
|
vsMenü.add(j);
|
|
}
|
|
JButton b1 = new JButton("OK");
|
|
b1.addActionListener(e -> cl.show(mainPanel, "mediumPanel"));
|
|
vsMenü.add(b1, BorderLayout.SOUTH);
|
|
mainPanel.add(vsMenü, "Videospiele");
|
|
cl.show(mainPanel, "Videospiele");
|
|
}
|
|
|
|
|
|
private static void myBooks(Kunde k) {
|
|
int i = k.ausgelieheneMedienLänge();
|
|
JPanel myBookMenu = new JPanel(new BorderLayout());
|
|
JPanel info = new JPanel(new GridLayout(i, 1, 10, 10));
|
|
JLabel text1 = new JLabel("Ihre ausgeliehenen Medien:");
|
|
myBookMenu.add(text1, BorderLayout.NORTH);
|
|
ArrayList<JLabel> jlabelList = Bibliothek.ausgelieheneListe(k);
|
|
for(JLabel j: jlabelList) {
|
|
info.add(j);
|
|
}
|
|
JButton b1 = new JButton("OK");
|
|
b1.addActionListener(e -> cl.show(mainPanel, "mediumPanel"));
|
|
myBookMenu.add(info, BorderLayout.CENTER);
|
|
myBookMenu.add(b1, BorderLayout.SOUTH);
|
|
mainPanel.add(myBookMenu, "AusgelieheneMedien");
|
|
cl.show(mainPanel, "AusgelieheneMedien");
|
|
}
|
|
|
|
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
}
|
|
|
|
|
|
}
|