import javax.swing.*;
import java.awt.*;
import java.awt.Color;
import java.awt.event.*;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JComponent;
import java.awt.event.ActionListener.*;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class CakeMakerFINAL extends JPanel
{
//Colours
public static final Color LIGHTBLUE = new Color (0xAD, 0xD8, 0xE6);
JFrame window;
JPanel panel = new JPanel(new GridBagLayout());
JPanel panel1 = new JPanel(new GridBagLayout());
boolean angelcake = false;
boolean mocha = false;
boolean vanilla = false;
boolean choco = false;
boolean berry = false;
boolean fruits = false;
boolean cream = false;
boolean birthday = false;
@Override public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.setColor(Color.RED);
g.drawRect (200,220,50,20);
repaint();
}
//methods to paint on graphics, (The buttons action)
public void myPaint(Graphics g)
{
if (angelcake)
{
g.setColor(Color.RED);
g.drawRect (30,30,50,20);
repaint();
}
if (mocha)
{
g.drawOval(10,10, 100, 100);
}
if (vanilla)
{
}
if (choco)
{
g.drawOval(10,10, 100, 100);
}
if (berry)
{
}
if (fruits)
{
g.drawOval(10,10, 100, 100);
}
if (cream)
{
}
if (birthday)
{
g.drawOval(10,10, 100, 100);
}
}
public CakeMakerFINAL()
{
//Frame and panel components
JFrame frame = new JFrame("Cake Maker Game");
frame.setVisible(true);
frame.setSize(600,700);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(panel, BorderLayout.SOUTH);
frame.getContentPane().add(panel1, BorderLayout.NORTH);
panel.setBackground(LIGHTBLUE);
//Positions buttons in JPanel
GridBagConstraints c = new GridBagConstraints();
//Labels
JLabel label1 = new JLabel("Type of Cake");
c.gridx = 0;
c.gridy = 0;
c.insets = new Insets(20,20,20,20);
panel.add(label1, c);
JLabel label2 = new JLabel("Icing");
c.gridx = 1;
c.gridy = 0;
panel.add(label2, c);
JLabel label3 = new JLabel("Decorations");
c.gridx = 2;
c.gridy = 0;
panel.add(label3, c);
//BUTTONS for selection
//Cake Choices
JButton angelcake = new JButton("AngelCake");
c.gridx = 0;
c.gridy = 1;
panel.add(angelcake, c);
angelcake.addActionListener(new Action());
JButton mocha = new JButton("Mocha");
c.gridx = 0;
c.gridy = 2;
panel.add(mocha, c);
mocha.addActionListener(new Action());
// Icing Choices
JButton vanilla = new JButton("Vanilla");
c.gridx = 1;
c.gridy = 1;
panel.add(vanilla, c);
vanilla.addActionListener(new Action());
JButton choco = new JButton("Choco");
c.gridx = 1;
c.gridy = 2;
panel.add(choco, c);
choco.addActionListener(new Action());
JButton berry = new JButton("Strawberry");
c.gridx = 1;
c.gridy = 3;
panel.add(berry, c);
berry.addActionListener(new Action());
// Decoration Choices
JButton fruits = new JButton("Fruits");
c.gridx = 2;
c.gridy = 1;
panel.add(fruits, c);
fruits.addActionListener(new Action());
JButton cream = new JButton("Whip Cream");
c.gridx = 2;
c.gridy = 2;
panel.add(cream, c);
cream.addActionListener(new Action());
JButton birthday = new JButton("Birthday!~");
c.gridx = 2;
c.gridy = 3;
panel.add(birthday, c);
birthday.addActionListener(new Action());
}
//Button Action, Draws graphic.
public class Action implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
if(e.getSource() == angelcake)
{
angelcake = true;
}
else if (e.getSource() == mocha)
{
mocha = true;
}
else if (e.getSource() == vanilla)
{
vanilla = true;
}
else if (e.getSource() == choco)
{
choco = true;
}
else if (e.getSource() == berry)
{
berry = true;
}
else if (e.getSource() == fruits)
{
fruits = true;
}
else if (e.getSource() == cream)
{
cream = true;
}
else if (e.getSource() == birthday)
{
birthday = true;
}
}
}
public static void main(String[] args)
{
CakeMakerFINAL cakemakerFinal = new CakeMakerFINAL();
}
}