Professional Documents
Culture Documents
Gui Project
Gui Project
(BOSS CAKE)
NAME
CLASS
: CS2442B
LECTURES NAME
INTRODUCTION
Our project is about cake purchasing system. Our customer can
choose their choice of cakes themselves. The customer will enter their
name and phone number for customer detail. Customer can choose
whether they want the whole cake or pieces of cake. There are five
different choices of cakes which are red velvet, choc indulgence,
fruitilicious, tiramisu and blueberry cheese cake. Customer will fill in
the quantity of the cake they want. The system will calculate the bill, if
the customer is the one of Boss Cakes member, they will get 10%
discount. The system will display the receipt of the cake that customer
chose.
CLASS MENU
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.util.*;
import java.text.*;
public Menu()
{ Container c = getContentPane();
image.setSize(800,219);
c.add(image);
c.setLayout(new FlowLayout());
c.setLayout(new BorderLayout());
RM9.50");
RM8.00");
RM7.50");
RM7.00");
RM6.50");
pnlSingle.add(lblSpRV);
pnlSingle.add(lblSpCI);
pnlSingle.add(lblSpF);
pnlSingle.add(lblSpT);
pnlSingle.add(lblSpBC);
RM120.00");
RM110.00");
RM100.00");
RM90.00");
RM80.00");
pnlWhole.add(lblWcRV);
pnlWhole.add(lblWcCI);
pnlWhole.add(lblWcF);
pnlWhole.add(lblWcT);
pnlWhole.add(lblWcBC);
pnlButton.add(jButton);
c.add(pnlImage, BorderLayout.NORTH);
c.add(pnlOrdr, BorderLayout.CENTER);
c.add(pnlButton, BorderLayout.SOUTH);
jButton.addActionListener(new java.awt.event.ActionListener()
{
//date purchased
private Date tday = new Date();
private SimpleDateFormat dateTday = new SimpleDateFormat("ddMMyy");
private SimpleDateFormat dateTday2 = new SimpleDateFormat("dd//MM/yyyy");
//format date
private GregorianCalendar g = new GregorianCalendar();
public BossCake()
{
Container c = getContentPane();
setTitle("BOSS CAKE");
setSize(800,500);
setLocation(100,80);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c.setLayout(new FlowLayout());
c.setLayout(new BorderLayout());
pnlInp.add(lblName);
pnlInp.add(txtName);
pnlInp.add(lblPhoneNo);
pnlInp.add(txtPhoneNo);
pnlInp.add(lblCake);
pnlInp.add(cbCake);
bg.add(rbMember[ind]);
pnlRadio.add(rbMember[ind]);
}
rbMember[0].setSelected(true);
pnlServ.add(pnlQuant);
btReset.addActionListener(this);
btExit.addActionListener(this);
btReceipt.addActionListener(this);
c.add(pnlImage, BorderLayout.NORTH);
c.add(pnlServ, BorderLayout.CENTER);
c.add(pnlButton, BorderLayout.SOUTH);
}
double totalPrice = 0.0, totalRV = 0.0, totalCI = 0.0, totalF = 0.0, totalT = 0.0, totalBC = 0.0;
//click button
if(jB == btReceipt)
{
String selection = (String)cbCake.getSelectedItem();
if(cbCake.getSelectedItem().equals("Whole cake"))
{ if(chkMenu[0].isSelected())
{
totalRV = quantRV * 120;
}
if(chkMenu[1].isSelected())
{
totalCI = quantCI * 110;
}
if(chkMenu[2].isSelected())
{
totalF = quantF * 100;
}
if(chkMenu[3].isSelected())
{
totalT = quantT * 90;
}
if(chkMenu[4].isSelected())
{
totalBC = quantBC * 80;
}
}
if(cbCake.getSelectedItem().equals("Single portion"))
{
if(chkMenu[0].isSelected())
{
totalRV = quantRV * 9.5;
}
if(chkMenu[1].isSelected())
{
totalCI = quantCI * 8.0;
}
if(chkMenu[2].isSelected())
{
totalF = quantF * 7.5;
}
if(chkMenu[3].isSelected())
{
totalT = quantT * 7.0;
}
if(chkMenu[4].isSelected())
{
totalBC = quantBC * 6.5;
}
if(rbMember[0].isSelected())
{
totalPrice = totalPrice - (0.1 * totalPrice);
}
else
{
totalPrice = totalPrice;
}
}
if(jB == btReset)
{ txtName.setText(null);
txtPhoneNo.setText(null);
txtName.setText("");
txtPhoneNo.setText("");
RVQuant.setText("");
CIQuant.setText("");
FQuant.setText("");
TQuant.setText("");
BCQuant.setText("");
}
if(jB == btReceipt)
{
if(txtName.getText().equalsIgnoreCase(""))
{
JOptionPane.showMessageDialog(null, "Enter name");
}
else
if(txtPhoneNo.getText().equalsIgnoreCase(""))
{
JOptionPane.showMessageDialog(null, "Enter phone number");
}
else
{ JOptionPane.showMessageDialog(null,
"\nName
:" + (txtName.getText()).toUpperCase() +
"\nPhone Number
:" + (txtPhoneNo.getText()).toUpperCase() +
"\nDate Purchased
:" + dateTday2.format(tday) +
: RM" + df.format(totalRV) +
"\n(2)CHOC INDULGENCE
: RM" + df.format(totalCI) +
"\n(3)FRUITILICIOUS
: RM" + df.format(totalF) +
"\n(4)TIRAMISU
: RM" + df.format(totalT) +
--------------" +
"\nTOTAL
: RM" + df.format(totalPrice),
if(jB == btExit)
{
System.exit(0);
}
}
catch(Exception a)
{
JOptionPane.showMessageDialog(null, "Please enter the information back.");
RVQuant.setText("");
CIQuant.setText("");
FQuant.setText("");
TQuant.setText("");
BCQuant.setText("");
}
}
}