Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Building a Menu List

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Building a Menu List

    Hi Guys,

    i am currently working on a project and would just like to add a bit more to it then needs be and also as I would liek to learn how to do it.

    Basically I have 3 classes at the moment

    CD ----> Artist ----> Concert

    what my plan was, is to add a public drop down menu to the Concert class that would allow me / the user to select the venue from the concert to one from the list and this would pop up when the constructor was 1st run.

    and then for this to change the current field "venue" to one from the drop down list although I have that bit already in mind as it wont be that hard.

    Sorry if there is not enough info just gve me a shout and I will put up what I have already.

    Thanks

    websey

    ... Oh and another thing is there any way to do a return statement on the same line for 2 fields


    as this doesnt seem to work
     
        public String getDetails()
        {
            return name, venue;
        }

    and nor does this
     
        public String getDetails()
        {
            return name,
            return venue;
        }
    Last edited by websey; November 15th, 2009 at 05:56 AM.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Building a Menu List

    In Java you can't return multiple values per method. Methods much return exactly one value (or be declared void and return exactly 0 values, or throw an exception).

    There are many solutions that could solve your problem.

    An easy one is to concatenate the two strings together:

    return name + " " + venue;

    This likely isn't going to be very effective, though. The second solution is to create two methods that return each item separately.

    public String getName()
    {
         return name;
    }
     
    public String getVenue()
    {
         return venue;
    }

    This is the implementation route I would take. It's concise, and you can get either value by itself.

    Another method you could take is to use an array/some other object to contain both strings and return that object:

    public String[] getDetails()
    {
         return new String[] {name,venue};
    }

Similar Threads

  1. Java program which can list all files in a given directory
    By JavaPF in forum Java Programming Tutorials
    Replies: 8
    Last Post: July 9th, 2013, 03:38 AM
  2. Replies: 1
    Last Post: October 23rd, 2009, 03:17 PM
  3. Which collection is best to do mathematical operation on it?
    By Sterzerkmode in forum Java Theory & Questions
    Replies: 1
    Last Post: May 7th, 2009, 04:48 AM
  4. Problem while implementing a basic user interface menu
    By Rastabot in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: April 3rd, 2009, 04:38 PM
  5. Recursive function based on Linked list
    By rosh72851 in forum Collections and Generics
    Replies: 1
    Last Post: March 9th, 2009, 06:23 PM