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 3 of 3

Thread: I cant wrap my head around this. (I'm also new here so if I'm posting wrong, have some patience!)

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Location
    England
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question I cant wrap my head around this. (I'm also new here so if I'm posting wrong, have some patience!)

    Okay, this is kinda hard to explain.

    I basically have a list of String variables which are named random objects. Those string variables are assigned colours so
    E.G. String blood = "red"
    String water = "clear"
    String sky = "blue"
    etc etc.... (sorry I dont know how to add the actual code i have written)

    Then I want the user to be able to enter an object into a JOptionPane box thing and receive an answer in the next JOptionPane box, saying
    what colour the object they have entered into the first box is.

    So i have - JOptionPane.showInputDialog("Enter an object to find out what colour it is");

    and I have - JOptionPane.showMessageDialog(null,);

    aaaaaaaaaaaaaaaaaaaand from then on my brain has gone silent.

    Thank you for any help! I know this is probably something easy but I'm just having a mind blank!


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: I cant wrap my head around this. (I'm also new here so if I'm posting wrong, have some patience!)

    It wont work that way. What you need is a relation between your "object" and it's colour. You cannot access a variables name. Have a look at HashMap<String, String>, use the Object as the key and it's colour as the value.

  3. #3
    Junior Member
    Join Date
    Jul 2013
    Location
    England
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I cant wrap my head around this. (I'm also new here so if I'm posting wrong, have some patience!)

    Quote Originally Posted by PhHein View Post
    It wont work that way. What you need is a relation between your "object" and it's colour. You cannot access a variables name. Have a look at HashMap<String, String>, use the Object as the key and it's colour as the value.
    I'm not entirely sure what that means, but I'll try and look at some YouTube examples, I think that would help me out. Thanks for letting me know I was on the wrong path anyway!

Similar Threads

  1. Re: Trying to wrap my head around Java
    By Sylis in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 10th, 2012, 01:54 PM
  2. Trying to wrap my head around Java
    By Sylis in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 10th, 2012, 08:10 AM
  3. how to wrap a pre-generics library
    By frumious in forum Object Oriented Programming
    Replies: 2
    Last Post: April 9th, 2012, 09:58 PM
  4. The Concept of Entities -- Can't wrap my mind around it.
    By RaustBD in forum Java Theory & Questions
    Replies: 2
    Last Post: November 21st, 2011, 08:42 PM
  5. Why wont the Button wrap?
    By Taylorleemusic in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 1st, 2010, 12:03 AM

Tags for this Thread