1. Welcome to PHCorner Forums. Take a moment to Sign up and gain unlimited access and extra privileges that guests are not entitled to, such as:

    All that and more! Registration is quick, simple and absolutely free. Join our community today!

Help Nga po utang na loob parang walang awa nyo na sa code kong ito Netbeans. Ordering Form

Discussion in 'Coding, Programming' started by JhoLou, Oct 18, 2013.

  1. JhoLou

    JhoLou Eternal Poster Established

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    /**
    *
    * @author DaveCastro
    */
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.event.ActionEvent;
    public class OrderingForm extends JFrame implements ItemListener, ActionListener{
    public JLabel title, Name,Address,Phone,Gender, Occasion, ifothers , Appetizer , MainDish, Dessert, total1, total,space1;
    public JTextField l1,l2,l3,l4,l5,l6;
    public JButton Submit,Reset;
    public JCheckBox male,female,app1,app2,app3,fp,fc,bula,fpo,mt,mg,icewcrem,ice ;
    public JComboBox occasion;
    public ButtonGroup gen,appetizer,maindish,dessert;
    public String myUser;
    double sum, sum1, vOccassion, vAppetizer,vAppetizer1,vAppetizer2,vMainDish,vMainDish1,vMainDish2,vDessert,vDessert1,vDessert2, vtotal= 0;
    String gender = "";
    String Appe1 , Appe2 ,Appe3;
    String Dish1 , Dish2 ,Dish3;
    String Des1 , Des2 ,Des3;
    public OrderingForm(){
    Login log = new Login();
    myUser = log.User.getText().toString();
    setTitle("Ordering Form");
    setSize(600,600);

    title = new JLabel("Ordering Form");
    //Name
    Name = new JLabel("Name: ");
    l1 = new JTextField();
    l2 = new JTextField();
    l3 = new JTextField();
    //Address
    Address = new JLabel("Address: ");
    l4 = new JTextField();

    //Phone
    Phone = new JLabel("Phone: ");
    l5 = new JTextField();
    //Gender
    Gender = new JLabel("Gender");
    gen = new ButtonGroup();
    male = new JCheckBox("Male");
    female = new JCheckBox("Female");
    gen.add(male);
    gen.add(female);
    //Occassion
    Occasion = new JLabel("Occassion: ");
    occasion = new JComboBox();
    occasion.addItem("---Select One---");
    occasion.addItem("Birthday");
    occasion.addItem("Wedding");
    occasion.addItem("Anniversary");
    occasion.addItem("Party");
    //Others
    ifothers = new JLabel("If others, please specify: ");
    l6 = new JTextField();
    //Appetizer
    Appetizer = new JLabel("Appetizer: ");
    appetizer = new ButtonGroup();
    space1= new JLabel("");
    app1 = new JCheckBox("Chicken wings-900Pesos");
    app2 = new JCheckBox("Chicken-300Pesos");
    app3 = new JCheckBox("Chicken w/o wings-100Pesos");
    //Main Dish
    MainDish = new JLabel("Main Dish: ");
    maindish = new ButtonGroup();
    fp = new JCheckBox("Fresh pig-20Pesos");
    fc = new JCheckBox("Fresh chicken-30Pesos");
    bula = new JCheckBox("Bulalo-5000Pesos");
    //Dessert
    Dessert = new JLabel("Dessert: ");
    dessert = new ButtonGroup();
    fpo = new JCheckBox("lolipop-20Pesos");
    mt = new JCheckBox("candy-1Pesos");
    mg = new JCheckBox("ice candy-5Pesos");

    //Total
    total1 = new JLabel("Total: ");
    total = new JLabel("");
    Submit = new JButton("Submit");
    Reset = new JButton("Reset");
    JPanel panel1 = new JPanel(new FlowLayout());
    JPanel namePanel = new JPanel(new GridLayout(1,1));
    JPanel addressPanel = new JPanel(new GridLayout(2,2));
    // JPanel phonePanel = new JPanel(new GridLayout(1,2));
    JPanel genderPanel = new JPanel(new GridLayout(1,2));
    JPanel occassionPanel = new JPanel(new GridLayout(1,2));
    JPanel appetizerPanel = new JPanel(new GridLayout(4,1));
    JPanel mainDishPanel = new JPanel(new GridLayout(4,1));
    JPanel dessertPanel = new JPanel(new GridLayout(4,1));
    JPanel panel2 = new JPanel(new FlowLayout());
    JPanel panel3 = new JPanel(new FlowLayout());
    //JPanel panel3 = new JPanel(new FlowLayout());

    setLayout(new GridLayout(10,6));

    add(panel1, BorderLayout.NORTH);
    add(namePanel);
    add(addressPanel);
    add(genderPanel);
    add(occassionPanel);
    add(appetizerPanel);
    add(mainDishPanel);
    add(dessertPanel);

    //add(panel2,BorderLayout.SOUTH);
    panel1.add(title);
    namePanel.add(Name);
    namePanel.add(l1);
    namePanel.add(l2);
    namePanel.add(l3);

    addressPanel.add(Address);
    addressPanel.add(l4);
    addressPanel.add(Phone);
    addressPanel.add(l5);

    genderPanel.add(Gender);
    genderPanel.add(male);
    genderPanel.add(female);

    occassionPanel.add(Occasion);
    occassionPanel.add(occasion);
    occassionPanel.add(ifothers);
    occassionPanel.add(l6);

    appetizerPanel.add(Appetizer);
    appetizerPanel.add(app1);
    appetizerPanel.add(app2);
    appetizerPanel.add(app3);

    mainDishPanel.add(MainDish);
    mainDishPanel.add(fp);
    mainDishPanel.add(fc);
    mainDishPanel.add(bula);

    dessertPanel.add(Dessert);
    dessertPanel.add(fpo);
    dessertPanel.add(mt);
    dessertPanel.add(mg);


    add(panel3, BorderLayout.SOUTH);
    panel3.add(total1);
    panel3.add(total);



    add(panel2, BorderLayout.SOUTH);
    panel2.add(Submit);
    panel2.add(Reset);

    female.addItemListener(this);
    male.addItemListener(this);
    occasion.addItemListener(this);
    app1.addItemListener(this);
    app2.addItemListener(this);
    app3.addItemListener(this);
    fp.addItemListener(this);
    fc.addItemListener(this);
    bula.addItemListener(this);
    fpo.addItemListener(this);
    mt.addItemListener(this);
    mg.addItemListener(this);

    Submit.addActionListener(this);
    Reset.addActionListener(this);

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);



    }
    public void itemStateChanged(ItemEvent e){
    if (e.getSource()==male){
    if (e.getStateChange()==ItemEvent.SELECTED){
    JOptionPane.showMessageDialog(null , "Male");
    }else if(e.getStateChange()==ItemEvent.DESELECTED){
    JOptionPane.showMessageDialog(null , "Female");

    }
    }
    if (e.getSource()==occasion){
    if (e.getStateChange()==ItemEvent.SELECTED){
    JOptionPane.showMessageDialog(null , "You Have Selected"+e.getItem().toString());
    }
    }
    //Appetizer
    double app;
    if(e.getSource()==app1){
    if(e.getStateChange()==ItemEvent.SELECTED){
    vAppetizer = +900;
    app=vAppetizer;
    Appe1 = "Chicken wings-900Pesos";

    }else if (e.getStateChange() == ItemEvent.DESELECTED) {
    vAppetizer = +0;
    app=vAppetizer;

    }
    }
    else if(e.getSource()==app2){
    if(e.getStateChange()==ItemEvent.SELECTED){
    vAppetizer1 = +300;
    app=vAppetizer1;
    Appe1 = "Chicken-300Pesos";
    }else if (e.getStateChange() == ItemEvent.DESELECTED) {
    vAppetizer1 = +0;
    app=vAppetizer1;
    }
    }

    else if(e.getSource()==app3){
    if(e.getStateChange()==ItemEvent.SELECTED){
    vAppetizer2 = +100;
    app=vAppetizer2;
    Appe1 = "Chicken w/o wings-100Pesos";
    }else if (e.getStateChange() == ItemEvent.DESELECTED) {
    vAppetizer2 = +0;
    app=vAppetizer2;
    }
    }
    //Main Dish
    double main;
    if(e.getSource()==fp){
    if(e.getStateChange()==ItemEvent.SELECTED){
    vMainDish = +20;
    main= vMainDish;
    Dish1 = "Fresh pig-20Pesos";
    }else if (e.getStateChange() == ItemEvent.DESELECTED) {
    vMainDish = +0;
    main= vMainDish;

    }
    }
    else if(e.getSource()==fc){
    if(e.getStateChange()==ItemEvent.SELECTED){
    vMainDish1 = +30;
    main= vMainDish1;
    Dish2= "Fresh chicken-30Pesos";
    }else if (e.getStateChange() == ItemEvent.DESELECTED) {
    vMainDish1 = +0;
    main= vMainDish1;
    }
    }
    else if(e.getSource()==bula){
    if(e.getStateChange()==ItemEvent.SELECTED){
    vMainDish2 = +5000;
    main= vMainDish2;
    Dish3 = "Bulalo-5000Pesos";
    }else if (e.getStateChange() == ItemEvent.DESELECTED) {
    vMainDish2 = +0;
    main= vMainDish2;
    }
    }

    //Dessert
    double dess;
    if(e.getSource()==fpo){
    if(e.getStateChange()==ItemEvent.SELECTED){
    vDessert = +20;
    dess=vDessert;
    Des1 = "lolipop-20Pesos";
    }else if(e.getStateChange()==ItemEvent.DESELECTED){
    vDessert = +0;
    dess=vDessert;
    }

    }
    else if(e.getSource()==mt){
    if(e.getStateChange()==ItemEvent.SELECTED){
    vDessert1 = +1;
    dess=vDessert1;
    Des2 = "candy-1Pesos";

    }else if(e.getStateChange()==ItemEvent.DESELECTED){
    vDessert1 = +0;
    dess=vDessert1;
    }
    }
    else if(e.getSource()==mg){
    if(e.getStateChange()==ItemEvent.SELECTED){
    vDessert2 = +5;
    dess=vDessert2;
    Des3 = "ice candy-5Pesos";
    }else if(e.getStateChange()==ItemEvent.DESELECTED){
    vDessert2 = +0;
    dess=vDessert2;
    }
    }
    sum1= vAppetizer + vAppetizer1 + vAppetizer2 + vMainDish + vMainDish1 + vMainDish2 + vDessert + vDessert1 + vDessert2;


    total.setText(""+sum1);
    }


    public void actionPerformed(ActionEvent e){


    if(e.getActionCommand().equals("Submit")){
    String l11, f11, m11 , t11, y11, q11, w11, e11, r11, u11, i11, p11, a11, z11, x11, c11, v11;
    l11 = l1.getText();
    f11 = l2.getText();
    m11 = l3.getText();
    t11 = l4.getText();
    y11 = l5.getText();
    q11 = male.getText();
    w11 = female.getText();
    e11 = occasion.getSelectedItem().toString();
    r11 = total.getText();

    PrintWriter pw=null;
    Scanner myData=null;

    try{
    pw=new PrintWriter(new FileOutputStream("Order.txt"));
    myData=new Scanner(new FileInputStream("Order.txt"));
    }catch(FileNotFoundException v){
    }
    String genRem = "";
    if(q11.equals("Male")){
    genRem = "Mr. ";
    }else if(q11.equals("Female")){
    genRem = "Ms. ";
    }
    pw.println("Name:"+genRem+l11+", "+f11+" "+m11);
    pw.println("Address:"+t11);
    pw.println("Phone:"+y11);
    //pw.println("Gender:"+q11);
    pw.println("Occasion:"+e11);
    pw.println("Appetizer:"+Appe1+" "+Appe2+" "+Appe3);
    pw.println("Dish:"+Dish1+" "+Dish2+" "+Dish3);
    pw.println("Dessert:"+Des1+" "+Des2+" "+Des3);
    pw.println("Total:"+total.getText().toString());



    String n="";
    String n2="";
    int ctr=0;
    while(myData.hasNext()){
    n=myData.nextLine();
    n2=myData.next();
    ctr++;
    System.out.println("n");
    System.out.println("n2");
    }



    if(l11.equals("")){
    JOptionPane.showMessageDialog(null,"ERROR!");
    }else if(f11.equals("")){
    JOptionPane.showMessageDialog(null,"ERROR!");
    }
    else if(m11.equals("")){
    JOptionPane.showMessageDialog(null,"ERROR!");
    }

    else{
    String id = "";
    String id1 = "";

    id = JOptionPane.showInputDialog(null,"YOUR ODER! \t \t \n"+gender +l11+ ", "+ f11+" "+m11+ "\n TOTAL AMOUNT:"+sum1);
    double number= Double.parseDouble(id);
    if (number<= sum1) {
    for(double num1=number; num1<sum1;num1++){
    id1 = JOptionPane.showInputDialog(null,"YOUR ODER! \t \t \n"+gender +l11+ ", "+ f11+" "+m11+ "\n TOTAL AMOUNT:"+sum1);
    double num2= Double.parseDouble(id1);

    {
    if(num2 >= sum1) {
    sum = num2 - sum1;

    JOptionPane.showMessageDialog(null,"Your Change"+sum);
    System.exit(0);



    } else if (e.getActionCommand().equals("Reset")) {
    l1.setText("");
    l2.setText("");
    l3.setText("");
    l4.setText("");
    l5.setText("");
    l6.setText("");

    }
    }
    }
    }
    }
    pw.println("Tender Amount:"+sum1);
    pw.println("Exchange:"+sum);
    pw.println("Chasier:"+myUser);
    pw.println("------------Thank You-----------");
    pw.close();
    myData.close();
    }

    }
    public static void main(String[] args) {
    OrderingForm myP = new OrderingForm();


    }}
     
  2. JOptionPane.showMessageDialog(null,"Your Change"+sum);
    dapat :
    JOptionPane.showMessageDialog(null,"Your Change"+sum1);

    pw.println("Tender Amount:"+sum1);
    pw.println("Exchange:"+sum);
    dapat:
    pw.println("Tender Amount:"+sum1);
    pw.println("Exchange:"+sum1);
     
    Jho Louie Ferrer likes this.
  3. JhoLou

    JhoLou Eternal Poster Established

    Salamat bro hehe,, marami pa kong mga code na dapat gawin :dead: sa HTML Merge sa CSS tsaka Javascript at JQuery XD
     
    mikedota2 likes this.
Tags / Keywords: