Results 1 to 10 of 10

Thread: Help!!!

  1. #1
    GabWit is offline Member
    Join Date
    Jan 2009
    Posts
    11
    Rep Power
    0

    Default Help!!!

    I copied this code from school and it says that ...
    public void itemStateChanged(ItemEvent it) has illegal start of expression and ';' expected could someone please tell me how to fix it



    }
    public void itemStateChanged(ItemEvent it)
    {
    if(it.getSource()==chkPencil)
    {
    intPencilCounter += 1;
    dblPencilTotal=dblPencilPrice*intpencilCounter;
    txaUserThings.serTexr("Pencils price: $" + dblPencilTotal +"\nNumber of pencils ordered "
    + intPencilCounter + "\n" + "\n");
    }

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default no closing?

    Looks like your method is missing a closing curly bracket "}"

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    GabWit is offline Member
    Join Date
    Jan 2009
    Posts
    11
    Rep Power
    0

    Default Closing

    I have a closing, I didn't copy the whole code so it doesn't appear if that's what you mean unless you mean somewhere else and if you do please tell me where.

  4. #4
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default

    It's going to be hard to help you if you don't show all the corresponding code... my crystal ball is in the shop for maintenance this week. What I was refering to is the following:
    Java Code:
    public void itemStateChanged(ItemEvent it)
    {
    if(it.getSource()==chkPencil)
    {
    intPencilCounter += 1;
    dblPencilTotal=dblPencilPrice*intpencilCounter;
    txaUserThings.serTexr("Pencils price: $" + dblPencilTotal +"\nNumber of pencils ordered "
    + intPencilCounter + "\n" + "\n");
    [COLOR="Red"][B]}//<-this is the closing bracket for the "if" statement... I don't see the closing bracket for the method[/B][/COLOR]
    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  5. #5
    GabWit is offline Member
    Join Date
    Jan 2009
    Posts
    11
    Rep Power
    0

    Default Full Code

    Here's my full code and has only one error the one I said before. Sorry i'm new with java so my knowledge is basically nothing



    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;

    public class eBusiness extends Applet implements ActionListener, ItemListener
    {
    Panel pnlTitle = new Panel ();
    Panel pnlTextfield = new Panel ();
    Panel pnlCheckbox = new Panel ();
    Panel pnlOption = new Panel ();
    Panel pnlOutput = new Panel ();
    Panel pnlOutput2 = new Panel ();
    Panel pnlStuff = new Panel ();

    final double dblPencilPrice = 1.00;
    final double dblPenPrice = 1.00;

    String strName;
    String strAddress;

    String strEmail;
    String strPhoneNumber;
    String strCellPhoneNumber;

    double dblPencilTotal;
    double dblPenTotal;
    double dblEraserTotal;
    double dblStaplerTotal;
    double dblRulerTotal;
    double dblPaperClipsTotal;
    double dblCalculatorTotal;
    double dblSharpenerTotal;
    double dblHighlighterTotal;
    double dblMarkersTotal;
    double dblTotal;
    double dblTax2;
    double dblFinalTotal;

    int intPencilCounter = 0;
    int intPenCounter = 0;
    int intEraserCounter = 0;
    int intStaplerCounter = 0;
    int intRulerCounter = 0;
    int intPaperClipsCounter = 0;
    int intCalculatorCounter = 0;
    int intSharpenerCounter = 0;
    int intHighlighterCounter = 0;
    int intMarkersCounter = 0;
    int intTotalCounter = 0;
    int intImageStapler = 0;

    TextField txtName = new TextField (15);
    TextField txtAddress = new TextField (30);
    TextField txtEmail = new TextField (20);
    TextField txtPhoneNumber = new TextField (10);
    TextField txtCellNumber = new TextField (10);

    Checkbox chkPencil = new Checkbox ("6 Pencils- $1.00");
    Checkbox chkPen = new Checkbox ("Pen- $1.00");

    CheckboxGroup cbgPayment = new CheckboxGroup ();
    Checkbox optCash = new Checkbox ("Cash", cbgPayment, false);
    Checkbox optCheque = new Checkbox ("Cheque", cbgPayment, false);
    Checkbox optVISA = new Checkbox ("Visa", cbgPayment, false);
    Checkbox optMasterCard = new Checkbox ("MasterCard", cbgPayment, false);
    Checkbox optAMEX = new Checkbox ("AMEX", cbgPayment, false);

    Button btnBuy = new Button("BUY");
    Button btnClear = new Button("CLEAR");
    Button btnExit = new Button("EXIT");

    TextArea txaUserInformation = new TextArea (10,25);
    TextArea txaUserThings = new TextArea (10,25);

    Label lblPayment = new Label ("");
    Label lblPayment = new Label ("");
    Label lblTotal = new Label ("");
    Label lblTax = new Label ("");
    Label lblFinalTotal = new Label ("");

    Font fntSetting = new Font ("Arial",Font.BOLD,50);
    Font fntSetting2 = new Font ("Arial",Font.BOLD,12);

    public void init()
    {

    setBackround(Color.black);

    add (pnlStuff);
    add (pnlTitle);
    add (pnlTextField);
    add (pnlCheckbox);
    add (pnlOption);
    add (pnlStuff);
    add (pnlOutput);
    add (pnlOutput2);

    pnlStuff.setBackround(Color.gray);
    pnlStuff.setLayout(new GridLayout(2,1));
    pnlStuff.add (new Label("ROW1 "));
    pnlStuff.add(new Label("ROW2 "));

    pnlTitle.setBackround(Color.yellow);
    pnlTitle.setLayout(new GridLayout(1,1));
    pnlTitle.add(new Label(" The Soccer Snop "));
    pnlTitle.setFont(fntSetting);

    pnlTextField.setBackround(Color.pink);
    pnlTextField.setLayout(new GridLayout(6,2));
    pnlTextField.add(new Label("Please enter yout information"));
    pnlTextField.add(new Label(""));
    pnlTextField.add(new Label("Name: "));
    txtName.setForeground(Color.cyan);
    txtName.setBackround(Color.black);

    pnlTextField.add(txt.Name);
    pnlTextField.add(new Label("Address: "));
    pnlTextField.add(txt.Address);

    pnlTextField.setFont(fntSetting2);

    pnlCheckbox.setBackround(Color.white);
    pnlCheckbox.setLayout(new GridLayout(11,1));
    pnlCheckbox.add(new Label("Please choose the item that you would like to buy"));
    pnlCheckbox.add(chkPencil);
    pnlCheckbox.add(chkPen);

    pnlCheckbox.setFont(fntSetting2);

    pnlOption.setBackround(Color.white);
    pnlOption.setLayout(new GridLayout(9,1));
    pnlOption.add(new Label("How do you want to pay"));
    pnlOption.add(optCash);
    pnlOption.add(optCheque);
    pnlOption.add(optMasterCard);
    pnlOption.add(optVISA);
    pnlOption.add(optAMEX);

    pnlOption.add(btnBuy);
    pnlOption.add(btnClear);
    pnlOption.add(btnExit);
    pnlOption.setFont(fntSetting2);

    pnlOutput.setBackround(Color.white);
    pnlOutput.setLayout(new GridLayout(2,2));
    pnlOutput.add(new Label("Your information"));
    pnlOutput.add(new Label("Items you want to buy"));
    pnlOutput.add(txaUserInformation);
    pnlOutput.add(txaUserThings);
    pnlOutput.setFont(fntSetting2);

    pnlOutput2.setBackround(Color.white);
    pnlOutput2.setLayout(new GridLayout(5,2));
    pnlOutput2.add(new Label("Option of payment"));
    pnlOutput2.add(lblPayment);
    pnlOutput2.add(new Label("Total number of items"));
    pnlOutput2.add(lblItem);
    pnlOutput2.add(new Label("Total"));
    pnlOutput2.add(lblTotal);
    pnlOutput2.add(new Label("Tax"));
    pnlOutput2.add(lblTax);
    pnlOutput2.add(new Label("Final Total"));
    pnlOutput2.add(lblFinalTotal);
    pnlOutput2.setFont(fntSetting2);

    txtName.addActionListener(this);
    txtAddress.addActionListener(this);
    txtEmail.addActionListener(this);
    txtPhoneNumber.addActionListener(this);
    btnBuy.addActionListener(this);
    btnClear.addActionListener(this);
    btnExit.addActionListener(this);

    chkPencil.addItemListener(this);
    chkPen.addItemListener(this);

    optCash.addItemListener(this);
    optCheque.addItemListener(this);
    optVISA.addItemListener(this);
    optMasterCard.addItemListener(this);
    optAMEX.addItemListener(this);

    }

    public void actionPerformed(ActionEvent event)
    {
    if (event.getSource()instanceof Button)
    {
    if (event.getSource()== btnBuy)
    {
    strName=txtName.getText();
    strAddress=txtAddress.getText();

    txaUserInformation.append("Name:" = strName + "\n" + "Address:" + strAddress
    + "\n" + "E-mail:" + strEmail + "\n" + "Phone Number:" + strPhoneNumber);

    dblTotal = dblPencilTotal + dblPenTotal + dblEraserTotal + dblStaplerTotal +
    dblRulerTotal + dblPaperClipsTotal + dblCalculatorTotal + dblSharpenerTotal + dblHighlighterTotal +
    dblMarkersTotal;
    lblTotal.setText("");
    lblTotal.setText("$" + dblFinalTotal);
    }
    if(event.getSource()==btnClear)
    {
    txaUserInformation.setText("");
    txaUserthings.setText("");
    txtName.setText("");
    txtAddress.setText("");
    txtEmail.setText("");
    txtPhoneNumber.setText("");
    lblPayment.setText("");
    lblItem.setText("");
    lblTotal.setText("");
    lblTax.setText("");
    lblFinalTotal.setText("");
    intTotalCounter=0;
    intPencilCounter=0;
    intPenCounter=0;
    intEraserCounter=0;
    intStaplerCounter=0;
    intTotalCounter=0;
    intRulerCounter=0;
    intPaperClipsCounter=0;
    intCalculatorCounter=0;
    intSharpenerCounter=0;
    intHighlighterCounter=0;
    intMarkersCounter=0;
    txtName.requestFocus();
    }
    if(event.getSource()==btnExit)
    {
    }
    }
    public void itemStateChanged(ItemEvent it)
    {

    if(it.getSource()==chkPencil)
    {

    intPencilCounter += 1;
    dblPencilTotal=dblPencilPrice*intpencilCounter;
    txaUserThings.serTexr("Pencils price: $" + dblPencilTotal +"\nNumber of pencils ordered "
    + intPencilCounter + "\n" + "\n");
    }

    intTotalCounter = intPencilCounter + intPenCounter + intEraserCounter + intStaplerCounter +
    intRulerCounter + intPaperClipsCounter + intCalculatorCounter + intSharpenerCounter +
    intHighlighterCounter + intMarkersCounter;
    lblItem.setText("");
    lblItem.setText(""+intTotalCounter);

    if(it.getSource()==optCash)
    {
    lblPayment.setText("");
    lblPayment.setText("CASH");
    }
    }
    }
    }

  6. #6
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default missing closing bracket

    Apparently, you have a missing closing bracket in the actionPerformed method. Check it out. When you correct that that missing closing bracket you will have an left over bracket at the very end of the code that you will have to get rid of.

    Luck,
    CJSL
    Last edited by CJSLMAN; 01-24-2009 at 07:58 PM. Reason: added somehting...
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  7. #7
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    if(it.getSource()==optCash)
    {
    lblPayment.setText("");
    lblPayment.setText("CASH");
    }//if end
    }//method end
    }//class end
    }//what tha...f... is it for?
    check it out

  8. #8
    GabWit is offline Member
    Join Date
    Jan 2009
    Posts
    11
    Rep Power
    0

    Default

    That fixed the initial problem but now i have 22 errors saying cannot find symbol for example all of the following code cannot find symbol. Anything that has pnlTextField or setBackround says cannot find symbol and txaUserInformation.append("Name:" = + strName + "\n" + "Address:" + strAddress + "\n" + "E-mail:" + strEmail + "\n" + "Phone Number:" + strPhoneNumber); says the error is unexpecterd type and another says operator + cannot be applied to java.lang.string

    Example of error code

    pnlTextField.setBackround(Color.pink);
    pnlTextField.setLayout(new GridLayout(6,2));
    pnlTextField.add(new Label("Please enter yout information"));
    pnlTextField.add(new Label(""));
    pnlTextField.add(new Label("Name: "));
    txtName.setForeground(Color.cyan);
    txtName.setBackround(Color.black);
    Last edited by GabWit; 01-24-2009 at 11:07 PM.

  9. #9
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    TextField txtName = new TextField (15);
    TextField txtAddress = new TextField (30);
    TextField txtEmail = new TextField (20);
    TextField txtPhoneNumber = new TextField (10);
    TextField txtCellNumber = new TextField (10);
    I can't see any txaUserInformation in the list :( I think it was deleted or some... Check it out. Maybe the code you pasted here is not complete?

  10. #10
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    if you don't have the txaUserInformation in the original context you should declare it by yourself

    TextField txaUserInformation=new TextField();
    I think that should solve the problem :)

Posting Permissions

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