Add partial exercise 4
This commit is contained in:
parent
c98c024952
commit
795bb4ac63
6 changed files with 233 additions and 1 deletions
9
de.hhn.ai.prog2.blatt3.pizzashop/src/app/Adresse.java
Normal file
9
de.hhn.ai.prog2.blatt3.pizzashop/src/app/Adresse.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
package app;
|
||||
|
||||
public class Adresse {
|
||||
private int id;
|
||||
private String street;
|
||||
private int houseNumber;
|
||||
private int zipCode;
|
||||
private String place;
|
||||
}
|
|
@ -2,6 +2,7 @@ package app;
|
|||
|
||||
public class App {
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println("Hello Java");
|
||||
MyPizzaShop myPizzaShop = new MyPizzaShop();
|
||||
myPizzaShop.setVisible(true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package app;
|
||||
|
||||
public class KontaktDaten {
|
||||
private int id;
|
||||
private int tel;
|
||||
private int mobile;
|
||||
private String email;
|
||||
}
|
30
de.hhn.ai.prog2.blatt3.pizzashop/src/app/Kunde.java
Normal file
30
de.hhn.ai.prog2.blatt3.pizzashop/src/app/Kunde.java
Normal file
|
@ -0,0 +1,30 @@
|
|||
package app;
|
||||
|
||||
public class Kunde {
|
||||
private int id;
|
||||
private String lastName;
|
||||
private String name;
|
||||
private String sex;
|
||||
private KontaktDaten kontaktDaten;
|
||||
private Adresse address;
|
||||
private Adresse shippingAddress;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the lastName
|
||||
*/
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
}
|
34
de.hhn.ai.prog2.blatt3.pizzashop/src/app/KundenService.java
Normal file
34
de.hhn.ai.prog2.blatt3.pizzashop/src/app/KundenService.java
Normal file
|
@ -0,0 +1,34 @@
|
|||
package app;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class KundenService {
|
||||
private List<Kunde> kunden = new ArrayList<Kunde>();
|
||||
|
||||
public void create(Kunde kunde) {
|
||||
kunden.add(kunde);
|
||||
}
|
||||
|
||||
// public void update(); // TODO:
|
||||
|
||||
public void delete(Kunde kunde) {
|
||||
kunden.remove(kunde);
|
||||
}
|
||||
|
||||
public Kunde read(int id) {
|
||||
for (Kunde kunde : kunden) {
|
||||
if (kunde.getId() == id)
|
||||
return kunde;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Kunde read(String name, String lastName) {
|
||||
for (Kunde kunde : kunden) {
|
||||
if (kunde.getName() == name && kunde.getLastName() == lastName)
|
||||
return kunde;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
150
de.hhn.ai.prog2.blatt3.pizzashop/src/app/MyPizzaShop.java
Normal file
150
de.hhn.ai.prog2.blatt3.pizzashop/src/app/MyPizzaShop.java
Normal file
|
@ -0,0 +1,150 @@
|
|||
package app;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Panel;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.WindowConstants;
|
||||
|
||||
public class MyPizzaShop extends JFrame {
|
||||
private static final long serialVersionUID = -5421020006317002203L;
|
||||
|
||||
private Container container;
|
||||
|
||||
public MyPizzaShop() {
|
||||
super("My Pizza Shop");
|
||||
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
this.setSize(800, 600);
|
||||
this.setJMenuBar(new MenuBar());
|
||||
container = this.getContentPane();
|
||||
container.setLayout(new BorderLayout());
|
||||
StatusPanel panel = new StatusPanel();
|
||||
container.add(panel, BorderLayout.SOUTH);
|
||||
showCenterPanel(new CenterPanel());
|
||||
}
|
||||
|
||||
public void showCenterPanel(JPanel panel) {
|
||||
container.add(panel, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
private class StatusPanel extends JPanel {
|
||||
private static final long serialVersionUID = -5777179157927719004L;
|
||||
|
||||
private StatusPanel() {
|
||||
this.setBorder(BorderFactory.createLineBorder(Color.black));
|
||||
JLabel label = new JLabel("Wilkommen");
|
||||
this.add(label);
|
||||
}
|
||||
}
|
||||
|
||||
private class MenuBar extends JMenuBar {
|
||||
private static final long serialVersionUID = 7457449847994117214L;
|
||||
|
||||
private MenuBar() {
|
||||
JMenu menu = new JMenu("Datei");
|
||||
JMenuItem quit = new JMenuItem("Beenden");
|
||||
quit.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
JPanel panel = new JPanel();
|
||||
panel.add(new JLabel("Hallo, das ist ein Begrüßungstext"));
|
||||
menu.add(panel);
|
||||
menu.add(quit);
|
||||
this.add(menu);
|
||||
|
||||
JMenu configurator = new JMenu("Konfigurator");
|
||||
JMenuItem listPizzas = new JMenuItem("Zeige definierte Pizzen");
|
||||
JMenuItem createPizza = new JMenuItem("Konfiguriere Pizza");
|
||||
createPizza.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
container.setVisible(!container.isVisible());
|
||||
}
|
||||
});
|
||||
configurator.add(listPizzas);
|
||||
configurator.add(createPizza);
|
||||
this.add(configurator);
|
||||
|
||||
JMenu management = new JMenu("Verwaltung");
|
||||
JMenuItem listStaff = new JMenuItem("Liste der Mitarbeiter");
|
||||
management.add(listStaff);
|
||||
this.add(management);
|
||||
|
||||
JMenu customer = new JMenu("Kunden");
|
||||
JMenuItem listCustomer = new JMenuItem("Liste der Kunden");
|
||||
JMenuItem manageCustomer = new JMenuItem("Kunde bearbeiten");
|
||||
customer.add(listCustomer);
|
||||
customer.add(manageCustomer);
|
||||
this.add(customer);
|
||||
|
||||
JMenu order = new JMenu("Bestellung");
|
||||
JMenuItem listOders = new JMenuItem("Liste der Bestellungen");
|
||||
order.add(listOders);
|
||||
this.add(order);
|
||||
}
|
||||
}
|
||||
|
||||
private class CenterPanel extends JPanel {
|
||||
private static final long serialVersionUID = 3527260169526726295L;
|
||||
private JLabel priceLabel = new JLabel();
|
||||
private int price = 200;
|
||||
|
||||
private CenterPanel() {
|
||||
this.setLayout(new GridLayout(5, 2));
|
||||
this.add(wrap(new JLabel("Name:")));
|
||||
this.add(wrap(new JTextField(20)));
|
||||
this.add(wrap(new JLabel("Größe:")));
|
||||
String[] pizzaSizes = new String[EnumSet.allOf(PizzaSize.class).size()];
|
||||
int i = 0;
|
||||
for (PizzaSize size : EnumSet.allOf(PizzaSize.class)) {
|
||||
pizzaSizes[i++] = size.getName();
|
||||
}
|
||||
this.add(wrap(new JList<String>(pizzaSizes)));
|
||||
this.add(wrap(new JLabel("Belag:")));
|
||||
String[] toppings = new String[EnumSet.allOf(Topping.class).size()];
|
||||
i = 0;
|
||||
for (Topping topping : EnumSet.allOf(Topping.class)) {
|
||||
toppings[i++] = topping.getName();
|
||||
}
|
||||
this.add(wrap(new JList<String>(toppings)));
|
||||
this.add(wrap(new JPanel()));
|
||||
this.add(wrap(priceLabel));
|
||||
this.add(wrap(new JButton("Abschicken")));
|
||||
this.add(wrap(new JButton("Ausdrucken")));
|
||||
setPrice(price);
|
||||
}
|
||||
|
||||
public void setPrice(int price) {
|
||||
this.price = price;
|
||||
priceLabel.setText("Preis: " + price + " Cent");
|
||||
}
|
||||
|
||||
private JPanel wrap(Component comp) {
|
||||
JPanel panel = new JPanel();
|
||||
panel.add(comp);
|
||||
return panel;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue