CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2007
    Posts
    3

    returning values from a list

    i have to make this food selector for a uni project and i was wondering if someone could help me i need it to when i click on the desert list it puts the information in to some lables.

    private void desertlstMouseClicked(java.awt.event.MouseEvent evt) {
    Food selectedfood = (Food)foodlist.getSelectedValue();
    if (selectedfood != null) {
    outPrintInfo(foodlist);
    }
    }
    private void outPrintInfo(Food e){
    pricelbl.setText(""+e.getCalAmount());
    calorieslbl.setText(""+e.getPrice());
    }

    this is what i have so far but it genarates a error :/
    C:\Users\houlahan\MenuApplication\src\FoodSelectorGUI.java:84: cannot find symbol
    symbol : method getSelectedValue()
    location: class FoodList
    Food selectedfood = (Food)foodlist.getSelectedValue();
    C:\Users\houlahan\MenuApplication\src\FoodSelectorGUI.java:86: setAllTextFields(Food) in FoodSelectorGUI cannot be applied to (FoodList)
    setAllTextFields(foodlist);
    any ideas please?
    thanks in advanced masterhoulahan.

  2. #2
    Join Date
    Mar 2009
    Posts
    9

    Re: returning values from a list

    If getSelectedValue() belongs to the class Food, and you're trying to convert foodlist, you should do it like this:
    Code:
    Food selectedfood = ((Food)foodlist).getSelectedValue();
    Yours won't work because the operator '.' has a higher priority than the operation of convertion.

  3. #3
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: returning values from a list

    The 'foodlist' variable clearly isn't the type you think it is. Unfortunately, you haven't posted the declaration or code for foodlist', so it's not possible to say more.

    I don't think Helstorm's suggestion has merit (i.e. is a 'foodlist' an instance of type 'Food'? unlikely - given the context, it's probably a list of type 'Food').

    To arrive at the simple is difficult...
    R. Elisha
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  4. #4
    Join Date
    Jan 2007
    Posts
    3

    Re: returning values from a list

    ive uploaded what i have got so far basicly i want it to return the price of the food and the amount of calories in t a lable when an item is selected from the jlist and the data comes from the food class.

    thanks again masterhoulahan.
    Attached Files Attached Files

  5. #5
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: returning values from a list

    I was hoping you'd take my hint, but apparently not.

    If you want to get the selected value, you should call getSelectedValue() on an object that has that method, e.g. desertlst.

    Incidentally, it's not good practice to use floating-point types like double for money values. Use an integral type such as long or BigInteger and store the money in the lowest denomination.

    Imagination is more important than knowledge...
    A. Einstein
    Last edited by dlorde; March 5th, 2009 at 06:16 AM.
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  6. #6
    Join Date
    Jan 2007
    Posts
    3

    Re: returning values from a list

    <3 saved my life :P thank you so much for your help!

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured