import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class GUI extends JFrame implements ActionListener
{
private JTabbedPane body;
private JPanel pEntry = new JPanel();
private JPanel pButton = new JPanel();
private JPanel pButton2 = new JPanel();
private JPanel pButton3 = new JPanel();
private JPanel pDisplay = new JPanel();
private JPanel pSearch = new JPanel();
private JPanel pBeer1 = new JPanel();
private JPanel pBeer2 = new JPanel();
private JPanel pBeer3 = new JPanel();
private JPanel pBeer4 = new JPanel();
private JPanel pBeer5 = new JPanel();
private int counter = 0;
private int counter2 = 0;
private JLabel lblTitle,lblID,lblName,lblbeer,lblbeer1,lblbeer2,lblbeer3,lblbeer4,lblbeer5;
private JLabel lblAmount;
private JLabel lblTitled,lblIDd,lblNamed,lblbeerd,lblbeer1d,lblbeer2d,lblbeer3d,lblbeer4d,lblbeer5d;
private JLabel lblAmountd;
private JLabel lblTitleR,lblIDR,lblNameR,lblbeerR,lblbeer1R,lblbeer2R,lblbeer3R,lblbeer4R,lblbeer5R;
private JLabel lblAmountR;
private JLabel lblTitle1,lblSearch,lblID1,lblName1,lblbeer1a,lblbeer11,lblbeer21,lblbeer31,lblbeer41,lblbeer51;
private JLabel lblAmount1;
private JLabel lblID2,lblName2,lblbeer2a,lblbeer12,lblbeer22,lblbeer32,lblbeer42,lblbeer52;
private JLabel lblAmount2;
private JLabel lblBlank,lblBlank2,lblBlank3;
private JTextField txtID,txtName,txtSearch,txtBQty1,txtBQty2,txtBQty3,txtBQty4,txtBQty5;
private JButton btnReset,btnSave,btnPrevious,btnNext,btnDisplay,btnSearch;
String choice;
private boolean flag,flag2=false,flag3=false;
Order[]orderRec;
public GUI()
{
super("Order");
body = new JTabbedPane();
Font customFont = new Font("Arial Black",Font.PLAIN,20);
Font customFont2 = new Font("Arial",Font.BOLD,12);
Color customBlue = new Color(50,150,255);
Color customRed = new Color(255,150,150);
Color customYellow = new Color(255,200,100);
Color customGray = new Color(230,230,230);
lblTitle = new JLabel("ORDER");
lblID = new JLabel(counter+1 +". Customer No:");
lblName = new JLabel("Staff Name:");
lblbeer = new JLabel("Beverage:");
lblbeer1 = new JLabel("Starker in cup(RM30)");
lblbeer2 = new JLabel("Starker in barrel(RM300)");
lblbeer3 = new JLabel("Chivas(RM228)");
lblbeer4 = new JLabel("Johnny walker's(RM234)");
lblbeer5 = new JLabel("Bacardi(RM228)");
lblAmount = new JLabel("Amount:");
lblBlank = new JLabel();
lblBlank2 = new JLabel();
lblBlank3 = new JLabel();
lblTitled = new JLabel("RECORD");
lblIDd = new JLabel(counter2+1 +". Customer No.:");
lblNamed = new JLabel("Staff Name:");
lblbeerd = new JLabel("Beverage:");
lblbeer1d = new JLabel("Starker in cup(RM30)");
lblbeer2d = new JLabel("Starker in barrel(RM300)");
lblbeer3d = new JLabel("Chivas(RM228)");
lblbeer4d = new JLabel("Johnny walker's(RM234)");
lblbeer5d = new JLabel("Bacardi(RM228)");
lblAmount = new JLabel("Amount:");
lblIDR = new JLabel();
lblNameR = new JLabel();
lblbeerR = new JLabel();
lblbeer1R = new JLabel();
lblbeer2R = new JLabel();
lblbeer3R = new JLabel();
lblbeer4R = new JLabel();
lblbeer5R = new JLabel();
lblAmount = new JLabel();
lblTitle1 = new JLabel("SEARCH RECORD");
lblSearch = new JLabel("Search Customer No.");
lblName1 = new JLabel("Staff Name:");
lblbeer1a = new JLabel("Beverage:");
lblbeer11 = new JLabel("Starker in cup(RM30)");
lblbeer21 = new JLabel("Starker in barrel(RM300)");
lblbeer31 = new JLabel("Chivas(RM228)");
lblbeer41 = new JLabel("Johnny walker's(RM234)");
lblbeer51 = new JLabel("Bacardi(RM228)");
lblAmount1 = new JLabel("Amount:");
lblName2 = new JLabel();
lblbeer2a = new JLabel();
lblbeer12 = new JLabel();
lblbeer22 = new JLabel();
lblbeer32 = new JLabel();
lblbeer42 = new JLabel();
lblbeer52 = new JLabel();
lblAmount2 = new JLabel();
txtID = new JTextField("",20);
txtName = new JTextField("",20);
txtBQty1 = new JTextField("",20);
txtBQty2 = new JTextField("",20);
txtBQty3 = new JTextField("",20);
txtBQty4 = new JTextField("",20);
txtBQty5 = new JTextField("",20);
txtSearch = new JTextField("",20);
btnReset = new JButton("RESET");
btnReset.setFont(customFont2);
btnReset.setBackground(customBlue);
btnReset.setForeground(Color.white);
btnReset.addActionListener(this);
btnSave = new JButton("SAVE");
btnSave.setFont(customFont2);
btnSave.setBackground(customBlue);
btnSave.setForeground(Color.white);
btnSave.addActionListener(this);
//btnTotal = new JButton("TOTAL");
//btnTotal.setFont(customFont2);
//btnTotal.setBackground(customBlue);
//btnTotal.setForeground(Color.white);
//btnTotal.addActionListener(this);
//btnTotal = new JButton("TOTAL");
//btnTotal.setFont(customFont2);
//btnTotal.setBackground(customBlue);
//btnTotal.setForeground(Color.white);
//btnTotal.addActionListener(this);
btnNext = new JButton("NEXT");
btnNext.setFont(customFont2);
btnNext.setBackground(customBlue);
btnNext.setForeground(Color.white);
btnNext.addActionListener(this);
btnNext.setEnabled(false);
btnPrevious = new JButton("PREVIOUS");
btnPrevious.setFont(customFont2);
btnPrevious.setBackground(customBlue);
btnPrevious.setForeground(Color.white);
btnPrevious.addActionListener(this);
btnPrevious.setEnabled(false);
btnDisplay = new JButton("DISPLAY");
btnDisplay.setFont(customFont2);
btnDisplay.setBackground(customBlue);
btnDisplay.setForeground(Color.white);
btnDisplay.addActionListener(this);
btnDisplay.setEnabled(false);
btnSearch = new JButton("SEARCH");
btnSearch.setFont(customFont2);
btnSearch.setBackground(customBlue);
btnSearch.setForeground(Color.white);
btnSearch.addActionListener(this);
btnSearch.setEnabled(false);
String input = JOptionPane.showInputDialog("Enter number of items in the array");
int num = Integer.parseInt(input);
orderRec = new Order[num];
for(int j=0;j<orderRec.length;j++)
{
orderRec[j] = new Order();
}
pEntry.setLayout(new GridLayout(13,2,0,2));
lblTitle.setBackground(customBlue);
lblTitle.setForeground(Color.black);
lblTitle.setFont(customFont);
lblBlank.setBackground(customBlue);
pEntry.add(lblTitle);
pEntry.add(lblBlank);
pEntry.add(lblID);
pEntry.add(txtID);
pEntry.add(lblName);
pEntry.add(txtName);
pEntry.add(lblbeer);
pEntry.add(new JLabel());
pEntry.add(lblbeer1);
pBeer1.setLayout(new GridLayout(0,4,0,2));
pBeer1.add(txtBQty1);
pBeer1.add(new JLabel());
pBeer1.add(new JLabel());
pBeer1.add(new JLabel());
pEntry.add(pBeer1);
pEntry.add(lblbeer2);
pBeer2.setLayout(new GridLayout(0,4,0,2));
pBeer2.add(txtBQty2);
pBeer2.add(new JLabel());
pBeer2.add(new JLabel());
pBeer2.add(new JLabel());
pEntry.add(pBeer2);
pEntry.add(lblbeer3);
pBeer3.setLayout(new GridLayout(0,4,0,2));
pBeer3.add(txtBQty3);
pBeer3.add(new JLabel());
pBeer3.add(new JLabel());
pBeer3.add(new JLabel());
pEntry.add(pBeer3);
pEntry.add(lblbeer4);
pBeer4.setLayout(new GridLayout(0,4,0,2));
pBeer4.add(txtBQty4);
pBeer4.add(new JLabel());
pBeer4.add(new JLabel());
pBeer4.add(new JLabel());
pEntry.add(pBeer4);
pEntry.add(lblbeer5);
pBeer5.setLayout(new GridLayout(0,4,0,2));
pBeer5.add(txtBQty5);
pBeer5.add(new JLabel());
pBeer5.add(new JLabel());
pBeer5.add(new JLabel());
pEntry.add(pBeer5);
pEntry.add(lblAmount);
pEntry.add(new JLabel());
pEntry.add(new JLabel());
pEntry.add(new JLabel());
pButton.setLayout(new GridLayout(0,3,3,2));
pButton.add(new JLabel());
//pButton.add(btnTotal);
pButton.add(btnReset);
pButton.add(btnSave);
pEntry.add(pButton);
pEntry.add(new JLabel());
pEntry.add(new JLabel());
lblTitled.setBackground(customRed);
lblTitled.setForeground(Color.black);
lblTitled.setFont(customFont);
lblBlank2.setBackground(customRed);
pDisplay.setLayout(new GridLayout(15,2,0,2));
pDisplay.add(lblTitled);
pDisplay.add(lblBlank2);
pDisplay.add(lblIDd);
pDisplay.add(lblIDR);
pDisplay.add(lblNamed);
pDisplay.add(lblNameR);
pDisplay.add(lblbeer);
pDisplay.add(new JLabel());
pDisplay.add(lblbeer1d);
pDisplay.add(lblbeer1R);
pDisplay.add(lblbeer2d);
pDisplay.add(lblbeer2R);
pDisplay.add(lblbeer3d);
pDisplay.add(lblbeer3R);
pDisplay.add(lblbeer4d);
pDisplay.add(lblbeer4R);
pDisplay.add(lblbeer5d);
pDisplay.add(lblbeer5R);
pDisplay.add(lblAmount);
pDisplay.add(new JLabel());
pDisplay.add(new JLabel());
pDisplay.add(new JLabel());
pButton2.setLayout(new GridLayout(0,3,3,2));
pButton2.add(btnDisplay);
pButton2.add(btnPrevious);
pButton2.add(btnNext);
pDisplay.add(pButton2);
pDisplay.add(new JLabel());
pDisplay.add(new JLabel());
lblTitle1.setBackground(customYellow);
lblTitle1.setForeground(Color.black);
lblTitle1.setFont(customFont);
lblBlank3.setBackground(customYellow);
pSearch.setLayout(new GridLayout(15,2,0,2));
pSearch.add(lblTitle1);
pSearch.add(lblBlank3);
pSearch.add(lblSearch);
pButton3.setLayout(new GridLayout(0,2,2,2));
pButton3.add(txtSearch);
pButton3.add(btnSearch);
pSearch.add(pButton3);
pSearch.add(new JLabel());
pSearch.add(new JLabel());
pSearch.add(lblID1);
pSearch.add(lblID2);
pSearch.add(lblName1);
pSearch.add(lblName2);
pSearch.add(lblbeer1a);
pSearch.add(new JLabel());
pSearch.add(lblbeer11);
pSearch.add(lblbeer12);
pSearch.add(lblbeer21);
pSearch.add(lblbeer22);
pSearch.add(lblbeer31);
pSearch.add(lblbeer32);
pSearch.add(lblbeer41);
pSearch.add(lblbeer42);
pSearch.add(lblbeer51);
pSearch.add(lblbeer52);
pSearch.add(lblAmount1);
pSearch.add(lblAmount2);
pSearch.add(new JLabel());
pSearch.add(new JLabel());
body.addTab("RECORD",null,pEntry,"Entry Record");
body.addTab("DISPLAY",null,pEntry,"Display Record");
body.addTab("SEARCH",null,pEntry,"Search Record");
body.setBackgroundAt(0,customBlue);
body.setBackgroundAt(1,customRed);
body.setBackgroundAt(2,customYellow);
body.setBackground(customGray);
add(body);
setSize(580,430);
setVisible(true);
}//End of GUI
public static void main(String[] args)throws AWTException
{
GUI adm = new GUI();
adm.addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}//End of main
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()== btnReset)
{
Reset();
}
if(ae.getSource()== btnSave)
{
if(flag == false)
{
Validate();
}
if(flag == true)
{
Save();
Reset();
if(counter == 0)
{
btnNext.setEnabled(false);
}
else if(flag == true)
{
btnNext.setEnabled(true);
}
counter++;
if(counter == 1)
{
btnDisplay.setEnabled(true);
btnSearch.setEnabled(true);
}
}
lblID.setText(counter+1 +".Customer No. :");
if(counter >= orderRec.length)
{
counter = 0;
lblID.setText(counter+1 +".Customer No. :");
}
flag = false;
}
if(ae.getSource()== btnDisplay)
{
Display();
flag3 = true;
btnDisplay.setEnabled(false);
if(counter == 1)
{
btnNext.setEnabled(false);
}
if(counter != 1)
{
btnNext.setEnabled(true);
}
if(ae.getSource()== btnNext)
{
counter2++;
if(counter2 == (counter-1))
{
btnNext.setEnabled(false);
}
else
{
btnNext.setEnabled(true);
}
if(counter2 == 4)
{
btnNext.setEnabled(false);
}
btnPrevious.setEnabled(true);
lblID.setText(counter2+1 +".Customer No. :");
Display();
}
if(ae.getSource()== btnPrevious)
{
counter2--;
if(counter == 0)
{
btnPrevious.setEnabled(false);
}
else
{
btnPrevious.setEnabled(true);
}
btnNext.setEnabled(true);
lblID.setText(counter2+1 +".Customer No. :");
Display();
}
if(ae.getSource()== btnSearch)
{
Validate2();
Search();
}
}
}// End of actionPerformed
//---Reset---
public void Reset()
{
txtID.setText("");
txtName.setText("");
txtBQty1.setText("");
txtBQty2.setText("");
txtBQty3.setText("");
txtBQty4.setText("");
txtBQty5.setText("");
}// End of reset
//---Save Record---
public void Save()
{
String name,temp;
int customer,Quantity1,Quantity2,Quantity3,Quantity4,Quantity5;
String temp1,temp2,temp3,temp4,temp5;
temp1 = txtID.getText();
customer = Integer.parseInt(temp1);
orderRec[counter].setCustomerNo(customer);
name = txtName.getText();
orderRec[counter].setStaffName(name);
temp1 = txtBQty1.getText();
Quantity1 = Integer.parseInt(temp1);
orderRec[counter].setQuantityA(Quantity1);
temp2 = txtBQty2.getText();
Quantity2 = Integer.parseInt(temp2);
orderRec[counter].setQuantityB(Quantity2);
temp3 = txtBQty3.getText();
Quantity3 = Integer.parseInt(temp3);
orderRec[counter].setQuantityC(Quantity3);
temp4 = txtBQty4.getText();
Quantity4 = Integer.parseInt(temp4);
orderRec[counter].setQuantityD(Quantity4);
temp5 = txtBQty5.getText();
Quantity5 = Integer.parseInt(temp5);
orderRec[counter].setQuantityE(Quantity5);
}// End of save
//---Dispaly Record---
public void Display()
{
int temp2;
String temp3;
double temp4;
temp2 = orderRec[counter2].getCustomerNo();
temp3 = Integer.toString(temp2);
lblIDR.setText(temp3);
lblNameR.setText(orderRec[counter2].getStaffName());
temp2 = orderRec[counter2].getQuantityA();
temp3 = Integer.toString(temp2);
lblbeer1R.setText(temp3);
temp2 = orderRec[counter2].getQuantityB();
temp3 = Integer.toString(temp2);
lblbeer2R.setText(temp3);
temp2 = orderRec[counter2].getQuantityC();
temp3 = Integer.toString(temp2);
lblbeer3R.setText(temp3);
temp2 = orderRec[counter2].getQuantityD();
temp3 = Integer.toString(temp2);
lblbeer4R.setText(temp3);
temp2 = orderRec[counter2].getQuantityE();
temp3 = Integer.toString(temp2);
lblbeer5R.setText(temp3);
}// End of Display
//---Search Record---
public void Search()
{
String str, temp7;
int a,cust,temp6,temp8,count=0;
double temp9;
flag2 = true;
//int[] idArray = new int[orderRec.length];
str = txtSearch.getText();
a = Integer.parseInt(str);
for(int k=0;k<orderRec.length;k++)
{
//idArray[k] = orderRec[k].getCustomerNo();
if(orderRec[k].getCustomerNo() == a)
{
flag2=true;
temp6 = orderRec[k].getCustomerNo();
temp7 = Integer.toString(temp6);
lblIDR.setText(temp7);
lblNameR.setText(orderRec[k].getStaffName());
temp6 = orderRec[k].getQuantityA();
temp7 = Integer.toString(temp6);
lblbeer1R.setText(temp7);
temp6 = orderRec[k].getQuantityB();
temp7 = Integer.toString(temp6);
lblbeer2R.setText(temp7);
temp6 = orderRec[k].getQuantityC();
temp7 = Integer.toString(temp6);
lblbeer3R.setText(temp7);
temp6 = orderRec[k].getQuantityD();
temp7 = Integer.toString(temp6);
lblbeer4R.setText(temp7);
temp6 = orderRec[k].getQuantityE();
temp7 = Integer.toString(temp6);
lblbeer5R.setText(temp7);
break;
}
else if(!(orderRec[k].getCustomerNo() == a))
{
flag2 = false;
}
}
if(flag2 == false)
JOptionPane.showMessageDialog(this,"Record not found.");
}// End of Search
//---Validation Checking---
public void Validate()throws ArithmeticException
{
flag = false;
int c = 0;
try{
c =Integer.parseInt(txtID.getText());
}catch(NumberFormatException nfx){
JOptionPane.showMessageDialog(this,"Invalid Customer No.");
}
if(txtID.getText().equals("")||txtName.getText().equals("")){
JOptionPane.showMessageDialog(this,"Please fill in staff name and customer no.");
}
else if(!txtName.getText().matches("([a-zA-Z]+|[a-zA-Z]+\\s[a-zA-Z]+)*")){
JOptionPane.showMessageDialog(this,"Invalid Name");
txtName.requestFocus();
}
else{
flag = true;
}
}// End of Validation
//---Search Validation Checking---
public void Validate2(){
if(txtSearch.getText().equals("")){
JOptionPane.showMessageDialog(this,"Please search ID");
txtSearch.requestFocus();
}
}// End of Search Validation Checking
}// End of class