Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: Gui program problem

  1. #1
    ryanCheng is offline Member
    Join Date
    Oct 2014
    Posts
    3
    Rep Power
    0

    Default Gui program problem

    Please help me :/
    I can't finish my project in my OOP subject,Ordering System Program,but i am finished with the layout and some processes.

    I have complication in which i don't know how to code a process that will record all the ordered items.
    i have items like [MS1]Taro Milk Tea.. and there's this textbox that will will get the inputted text and get the quantity of it by JOptionPane.
    There's this another JOptionPane that will show the order(s) when "Show Order" button is clicked.
    My main problem is i can't record additional items if i want to add more . and my variables are all stored in an array.

    Please HELP! it will be a big HELP to me if you can or give me some hint or reference or suggest a different way of getting the order,quantity,price of it and Sum all of it and Display the Ordered items...
    THANK YOU SO MUCH ! :'< my professor required that we used inheritance so i have 2 subclasses..
    ************************************************** ************************

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    public class MilkteaGUI extends JFrame implements ActionListener,WindowListener {

    MtGUIProcess mg = new MtGUIProcess();
    Label cardNo = new Label("Card Number:");
    Label lblName = new Label("Member's Name: ");
    Label lblcode = new Label("Enter MilkTea/Shake Code: ");
    TextField tfcardNo = new TextField();

    Label Name = new Label();
    TextField tfcode = new TextField();
    Label lblmenu = new Label("MENU");
    Label lblmt = new Label("MilkTeas");
    Label lblms = new Label("MilkShakes");

    Label mt1 = new Label("[MT1]Royal Milk Tea 120");
    Label mt2 = new Label("[MT2]Taro Milk Tea 100");
    Label mt3 = new Label("[MT3]Jasmine Milk Tea 115");
    Label mt4 = new Label("[MT4]Chocolate Milk Tea 100");
    Label mt5 = new Label("[MT5]Strawberry Milk Tea 100");
    Label mt6 = new Label("[MT6]Oreo Milk Tea 120");

    Label ms1 = new Label("[MS1]Strawberry Milk Shake 90");
    Label ms2 = new Label("[MS2]Almond Milk Shake 95");
    Label ms3 = new Label("[MS3]Mocha Milk Shake 85");
    Label ms4 = new Label("[MS4]Chocolate Milk Shake 85");
    Label ms5 = new Label("[MS5]Melon Milk Shake 90");
    Label ms6 = new Label("[MS6]Vanilla Milk Shake 80");
    Button btAdd = new Button("Add");
    Button btOrder = new Button("Show Order(s)");
    Button btReset = new Button("Reset Order(s)");
    Button btSubOrder = new Button("SUBMIT ORDER(S)");
    Button btLoad = new Button("Load Account");
    Button btQuit = new Button("Quit");


    MilkteaGUI() {
    setTitle("PhanTea's Milk Tea");
    Panel p = new Panel();

    p.setLayout(null);
    // Set Location of the Components
    cardNo.setBounds (15,5,90,20);
    tfcardNo.setBounds (130,5,100,20);

    lblName.setBounds (15,45,120,20);
    Name.setBounds (150,45,200,25);

    lblmenu.setBounds (240,90,80,20);
    lblmt.setBounds (30,115,100,20);
    mt1.setBounds (40,145,220,20);
    mt2.setBounds (40,165,220,20);
    mt3.setBounds (40,185,220,20);
    mt4.setBounds (280,145,225,20);
    mt5.setBounds (280,165,225,20);
    mt6.setBounds (280,185,225,20);

    lblms.setBounds (30,215,100,20);
    ms1.setBounds (40,245,235,20);
    ms2.setBounds (40,265,235,20);
    ms3.setBounds (40,285,235,20);
    ms4.setBounds (280,245,235,20);
    ms5.setBounds (280,265,235,20);
    ms6.setBounds (280,285,235,20);

    lblcode.setBounds (30,330,200,22); tfcode.setBounds(250,330,50,20);
    btAdd.setBounds (315,330,50,20);

    btLoad.setBounds (250,5,100,23);
    btOrder.setBounds (35,380,130,40); btSubOrder.setBounds(190,380,160,60);
    btReset.setBounds (370,380,140,40);

    btQuit.setBounds (90,350,80,25);
    // add the components
    p.add(cardNo); p.add(tfcode); p.add(btAdd);
    p.add(btSubOrder); p.add(lblName); p.add(tfcardNo);
    p.add(btReset);
    p.add(Name);
    p.add(lblmenu);
    p.add(lblmt);
    p.add(mt1);
    p.add(mt2);
    p.add(mt3);
    p.add(mt4);
    p.add(mt5);
    p.add(mt6);
    p.add(lblms);
    p.add(ms1);
    p.add(ms2);
    p.add(ms3);
    p.add(ms4);
    p.add(ms5);
    p.add(ms6);
    p.add(btLoad);
    p.add(lblcode);
    p.add(btOrder);
    // p.add(btQuit);

    btLoad.addActionListener(this);
    btOrder.addActionListener(this);
    btSubOrder.addActionListener(this);
    btAdd.addActionListener(this);
    btQuit.addActionListener(this);

    tfcode.setEditable(false);
    lblmenu.setAlignment(Label.CENTER);
    lblcode.setFont(new Font("Arial",Font.BOLD,14));
    btOrder.setFont(new Font("Century Gothic",Font.BOLD,16));
    btSubOrder.setFont(new Font("Century Gothic",Font.BOLD,16));
    btReset.setFont(new Font("Century Gothic",Font.BOLD,16));
    Name.setFont(new Font("Arial",Font.BOLD,18));
    lblmenu.setFont(new Font("Century Gothic",Font.BOLD,18));
    lblmt.setFont(new Font("Century Gothic",Font.BOLD,14));
    lblms.setFont(new Font("Century Gothic",Font.BOLD,14));
    add(p);
    addWindowListener(this);
    }


    public static void main(String [] args) {
    MilkteaGUI m = new MilkteaGUI();
    m.setVisible(true);
    m.setSize(550,500);
    m.setResizable(false);
    m.setLocation(320,150);
    }

    public void actionPerformed(ActionEvent e){
    if(e.getSource() == btLoad ){
    loadAcct(); }
    else if(e.getSource() == btAdd) {
    getOrders(); }
    else if(e.getSource() == btOrder) {
    printOrders();
    }

    }
    // Initialize Variables needed
    int qty,ctr,jQty;
    float totPrc=.2f,prc;
    String cardNum,name,iCode,orders;


    public void getOrders(){
    iCode = tfcode.getText().trim();
    if(iCode.length() > 0) {
    // String [] orders = new String[50];
    String [] milkTS = new String[20];
    // for(ctr =0; ctr< milkTS.length;ctr++)
    orders=mg.getOrder(iCode);
    totPrc=mg.tempGet1(iCode);

    if(totPrc == 0)
    {
    Toolkit.getDefaultToolkit().beep();
    JOptionPane.showMessageDialog(null," Item Code Not Found "
    + "\n Please Enter a Valid Item Code");
    } else {

    jQty = Integer.parseInt(JOptionPane.showInputDialog(null, orders,
    "Enter Quantity Here")); }
    } else {
    JOptionPane.showMessageDialog(null,"Please Enter an Item Code");
    }
    }

    public void printOrders(){
    orders=mg.getOrder(iCode);
    totPrc=mg.calcOrder(iCode,jQty);

    JOptionPane.showMessageDialog(null,"Order(s) : \n" +
    orders + "\nQuantity: "+ jQty +
    "\nTotal Price: "+ totPrc +"\n");

    }

    public void loadAcct() {
    cardNum = tfcardNo.getText().trim();
    if(cardNum.length() > 0){
    name = mg.getCardNo(cardNum);
    prc= mg.tempGet(cardNum);

    if(prc == 0 ){
    Toolkit.getDefaultToolkit().beep();
    JOptionPane.showMessageDialog(null," Card Number Not Found. "
    + "\n Please Enter a Valid Card Number."); tfcardNo.setText("");
    } else {
    Name.setText(name);
    tfcode.setEditable(true); }
    } else {
    JOptionPane.showMessageDialog(null,"Please Enter a Card Number");
    tfcardNo.requestFocus(); Toolkit.getDefaultToolkit().beep();
    }
    }

    public void windowClosing(WindowEvent E){
    System.exit(0); }
    public void windowClosed(WindowEvent e){}
    public void windowIconified(WindowEvent e){}
    public void windowDeiconified(WindowEvent e){}
    public void windowActivated(WindowEvent e){}
    public void windowDeactivated(WindowEvent e){}
    public void windowOpened(WindowEvent e){}

    }
    ************************************************** *************************
    import javax.swing.*;
    public class MtGUIData {
    String [] cardNo = {"M143","M342","M544","M1001"};
    String [] names = {"Reynaldo Buesing","Ryan Vince Cheng","Rica Donne Malana","Beatrix Espiridion"};
    String [] milkTS = {"Royal Milk Tea","Taro Milk Tea","Jasmine Milk Tea",
    "Chocolate Milk Tea","Strawberry Milk Tea","Oreo Milk Tea",
    "Strawberry Milk Shake","Almond Milk Shake","Mocha Milk Shake",
    "Chocolate Milk Shake","Melon Milk Shake","Vanilla Milk Shake"};
    String [] codeNo = {"MT1","MT2","MT3","MT4","MT5","MT6","MS1","MS2"," MS3","MS4","MS5","MS6",};
    int [] price = {120,100,115,100,100,120,
    90,100,85,85,95,80};
    int[] qty = new int[20];
    float totPrice1=0.2f;

    int idx;
    public String getCardNo(String cno) {
    for(idx=0; idx < cardNo.length;idx++)
    if(cardNo[idx].equalsIgnoreCase(cno))
    return names[idx];
    return "Not Found";
    }
    public float tempGet(String cno) {
    for(idx=0; idx < cardNo.length;idx++)
    if(cardNo[idx].equalsIgnoreCase(cno))
    return price[idx];
    return 0;
    }
    public float tempGet1(String ic) {
    for(idx=0; idx < codeNo.length;idx++)
    if(codeNo[idx].equalsIgnoreCase(ic))

    return price[idx];
    return 0;
    }
    public String getOrder(String iC) {
    for(idx=0; idx< milkTS.length; idx++)
    if(codeNo[idx].equalsIgnoreCase(iC))

    return milkTS[idx];
    return "Not Found";

    }


    }
    ************************************************** ****************************************
    import java.awt.*;
    import javax.swing.*;

    public class MtGUIProcess extends MtGUIData {

    public float calcOrder(String s,int jqty) {
    float tP=0;
    for(idx=0; idx < milkTS.length;idx++)
    if(codeNo[idx].equalsIgnoreCase(s))
    tP = jqty * price[idx];
    return tP;
    }
    public float summOrder(String s,float tPrice){
    float [] allPrc = new float[20];
    for(idx=0; idx< milkTS.length; idx++)
    if(codeNo[idx].equalsIgnoreCase(s))
    if(codeNo[idx] != null)
    allPrc[idx] += tPrice;
    return allPrc[idx];

    }
    }
    Attached Thumbnails Attached Thumbnails Gui program problem-mpic.png   Gui program problem-mpic2.png  
    Last edited by ryanCheng; 10-11-2014 at 04:52 PM.

  2. #2
    ryanCheng is offline Member
    Join Date
    Oct 2014
    Posts
    3
    Rep Power
    0

    Default Re: Gui program problem

    i Typed quantity = 2 and it is functioning well but incomplete. :'(
    Please help me :'< i need to finish this within 48 hours :(
    Last edited by ryanCheng; 10-11-2014 at 04:37 PM.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: Gui program problem

    How to ask questions the smart way

    To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that clearly show where you have a problem.

    db
    ryanCheng likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    ryanCheng is offline Member
    Join Date
    Oct 2014
    Posts
    3
    Rep Power
    0

    Default Re: Gui program problem

    Ok sir! Thank you so much!

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: Gui program problem

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. problem with this program
    By bunty83 in forum New To Java
    Replies: 7
    Last Post: 11-01-2011, 11:05 PM
  2. Small problem with problem with Java, C++ parse program.
    By dragstang86 in forum New To Java
    Replies: 4
    Last Post: 10-30-2011, 03:43 AM
  3. Can anyone tell me problem in this program ??
    By sahildave1991 in forum AWT / Swing
    Replies: 3
    Last Post: 07-02-2010, 05:37 PM
  4. Problem in Program
    By Abbinormal in forum New To Java
    Replies: 9
    Last Post: 01-08-2010, 03:38 AM
  5. program problem
    By amith in forum AWT / Swing
    Replies: 12
    Last Post: 05-16-2008, 08:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •