package mcdonalds;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
/**
*
* @author Dauzo
*/
public class GUI extends JFrame{
private JButton b1, b2, b3, b4, b5, b6, b7, b8, buttonExit;
private JButton chickenb1, chickenb2, chickenb3, chickenb4, chickenb5, chickenb6, chickenb7, chickenb8,
chickenb9, chickenb10, chickenexit;
private JLabel bestellungLabel, ware1, ware2;
private int i = 1, o = 1;
private JFrame win;
private JPanel buttonLayout = new JPanel (new GridLayout(0,4));
private JPanel warenkorbLayout = new JPanel (new FlowLayout(FlowLayout.LEFT));
private JPanel chickenLayout = new JPanel (new GridLayout(2,5));
private JPanel detailLayout = new JPanel(new FlowLayout(FlowLayout.RIGHT));
static final String gapList[] = {"0", "10", "15", "20"};
final static int maxGap = 20;
public String menuListe[] = {"Chicken & Shrimps", "Menus", "Happy Meal", "Salate",
"Desserts", "Beilagen", "Getränke", "Easy Morning"};
public String chickenListe[] = {"Chicken Croks", "Share Box", "Prime Chicken Filets", "Chicken McNuggets\n(4 Stk.)",
"Chicken McNuggets(6 Stk.", "Chicken McNuggets(9 Stk.)", "Chicken McNueggets(20 Stk.)",
"Chicken Wings", "Shrimps", "McChicken"};
/* Hauptfenster */
public GUI(){
win = new JFrame("McDonalds");
win.setSize(800,550);
win.setResizable(false);
win.setLocationRelativeTo(null);
win.setDefaultCloseOperation(EXIT_ON_CLOSE);
ImageIcon chicken = new ImageIcon("../images/chicken.jpg");
ImageIcon menu = new ImageIcon("../images/menu.jpg");
ImageIcon happymeal = new ImageIcon("../images/happymeal.jpg");
ImageIcon salat = new ImageIcon("../images/salat.jpg");
ImageIcon dessert = new ImageIcon("../images/dessert.jpg");
ImageIcon beilagen = new ImageIcon("../images/beilagen.jpg");
ImageIcon getraenke = new ImageIcon("../images/getraenke.jpg");
ImageIcon fruestueck = new ImageIcon("../images/fruestueck.jpg");
win.setLayout (new BorderLayout());
buttonLayout.add(b1 = new JButton(menuListe[0], chicken));
b1.setVerticalTextPosition(SwingConstants.BOTTOM);
b1.setHorizontalTextPosition(SwingConstants.CENTER);
b1.addActionListener(new Listener());
buttonLayout.add(b2 = new JButton(menuListe[1], menu));
b2.setVerticalTextPosition(SwingConstants.BOTTOM);
b2.setHorizontalTextPosition(SwingConstants.CENTER);
b2.addActionListener(new Listener());
buttonLayout.add(b3 = new JButton(menuListe[2], happymeal));
b3.setVerticalTextPosition(SwingConstants.BOTTOM);
b3.setHorizontalTextPosition(SwingConstants.CENTER);
buttonLayout.add(b4 = new JButton(menuListe[3], salat));
b4.setVerticalTextPosition(SwingConstants.BOTTOM);
b4.setHorizontalTextPosition(SwingConstants.CENTER);
buttonLayout.add(b5 = new JButton(menuListe[4], dessert));
b5.setVerticalTextPosition(SwingConstants.BOTTOM);
b5.setHorizontalTextPosition(SwingConstants.CENTER);
buttonLayout.add(b6 = new JButton(menuListe[5], beilagen));
b6.setVerticalTextPosition(SwingConstants.BOTTOM);
b6.setHorizontalTextPosition(SwingConstants.CENTER);
buttonLayout.add(b7 = new JButton(menuListe[6], getraenke));
b7.setVerticalTextPosition(SwingConstants.BOTTOM);
b7.setHorizontalTextPosition(SwingConstants.CENTER);
buttonLayout.add(b8 = new JButton(menuListe[7], fruestueck));
b8.setVerticalTextPosition(SwingConstants.BOTTOM);
b8.setHorizontalTextPosition(SwingConstants.CENTER);
win.add (buttonLayout, BorderLayout.CENTER);
win.add (warenkorbLayout, BorderLayout.SOUTH);
warenkorb();
win.setVisible(true);
}
private void warenkorb(){
warenkorbLayout.add(bestellungLabel = new JLabel("Bestellung: \n"));
warenkorbLayout.add(buttonExit = new JButton("Exit"));
buttonExit.addActionListener(new Listener());
warenkorbLayout.add(ware1 = new JLabel());
warenkorbLayout.add(ware2 = new JLabel());
}
/* Fenster für "Chicken & Shrimps" */
private void winChicken(){
win.add (chickenLayout, BorderLayout.CENTER);
win.add (detailLayout, BorderLayout.SOUTH);
ImageIcon chickencroks = new ImageIcon("../images/chicken/chickencrocs.jpg");
ImageIcon sharebox = new ImageIcon("../images/chicken/sharebox.jpg");
ImageIcon chickenfilets = new ImageIcon("../images/chicken/chickenfilets.jpg");
ImageIcon mcnuggets4stk = new ImageIcon("../images/chicken/mcnuggets4.jpg");
ImageIcon mcnuggets6stk = new ImageIcon("../images/chicken/mcnuggets6.jpg");
ImageIcon mcnuggets9stk = new ImageIcon("../images/chicken/mcnuggets9.jpg");
ImageIcon mcnuggets20stk = new ImageIcon("../images/chicken/mcnuggets20.jpg");
ImageIcon chickenwings = new ImageIcon("../images/chicken/chickenwings.jpg");
ImageIcon shrimps = new ImageIcon("../images/chicken/shrimps.jpg");
ImageIcon mcchicken = new ImageIcon("../images/chicken/mcchicken.jpg");
chickenLayout.add(chickenb1 = new JButton(chickenListe[0], chickencroks));
chickenb1.setVerticalTextPosition(SwingConstants.BOTTOM);
chickenb1.setHorizontalTextPosition(SwingConstants.CENTER);
chickenb1.addActionListener(new Listener());
chickenLayout.add(chickenb2 = new JButton(chickenListe[1], sharebox));
chickenb2.setVerticalTextPosition(SwingConstants.BOTTOM);
chickenb2.setHorizontalTextPosition(SwingConstants.CENTER);
chickenb2.addActionListener(new Listener());
chickenLayout.add(chickenb3 = new JButton(chickenListe[2], chickenfilets));
chickenb3.setVerticalTextPosition(SwingConstants.BOTTOM);
chickenb3.setHorizontalTextPosition(SwingConstants.CENTER);
chickenLayout.add(chickenb4 = new JButton(chickenListe[3], mcnuggets4stk));
chickenb4.setVerticalTextPosition(SwingConstants.BOTTOM);
chickenb4.setHorizontalTextPosition(SwingConstants.CENTER);
chickenLayout.add(chickenb5 = new JButton(chickenListe[4], mcnuggets6stk));
chickenb5.setVerticalTextPosition(SwingConstants.BOTTOM);
chickenb5.setHorizontalTextPosition(SwingConstants.CENTER);
chickenLayout.add(chickenb6 = new JButton(chickenListe[5], mcnuggets9stk));
chickenb6.setVerticalTextPosition(SwingConstants.BOTTOM);
chickenb6.setHorizontalTextPosition(SwingConstants.CENTER);
chickenLayout.add(chickenb7 = new JButton(chickenListe[6], mcnuggets20stk));
chickenb7.setVerticalTextPosition(SwingConstants.BOTTOM);
chickenb7.setHorizontalTextPosition(SwingConstants.CENTER);
chickenLayout.add(chickenb8 = new JButton(chickenListe[7], chickenwings));
chickenb8.setVerticalTextPosition(SwingConstants.BOTTOM);
chickenb8.setHorizontalTextPosition(SwingConstants.CENTER);
chickenLayout.add(chickenb9 = new JButton(chickenListe[8], shrimps));
chickenb9.setVerticalTextPosition(SwingConstants.BOTTOM);
chickenb9.setHorizontalTextPosition(SwingConstants.CENTER);
chickenLayout.add(chickenb10 = new JButton(chickenListe[9], mcchicken));
chickenb10.setVerticalTextPosition(SwingConstants.BOTTOM);
chickenb10.setHorizontalTextPosition(SwingConstants.CENTER);
detailLayout.add(chickenexit = new JButton("Zurück zur Auswahlliste"));
chickenexit.addActionListener(new Listener());
win.setVisible(true);
}
private class Listener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
/* chickenExit geht zurück zur Auswahlfenster (Hauptfenster) */
if(e.getSource() == chickenexit){
buttonLayout.setVisible(true);
chickenLayout.setVisible(false);
detailLayout.setVisible(false);
}
/* buttonExit beendet das ganze Programm */
if(e.getSource() == buttonExit){
win.dispose();
System.exit(0);
}
if(e.getSource() == b1){
buttonLayout.setVisible(false);
chickenLayout.setVisible(true);
detailLayout.setVisible(true);
winChicken();
}
if(e.getSource() == chickenb1){
ware1.setText(chickenListe[0] + " x" + i);
i++;
}
if(e.getSource() == chickenb2){
ware2.setText(chickenListe[1] + " x" + o);
o++;
}
}
}
}