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: If statement help

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default If statement help

    Hey guys,

    I have a school project where we have to design a quiz game (doesn't have to be graphically amazing), but it does have to look somewhat nice.

    I'm trying to create a way to allow the user to select the font color as well as background color before actually starting the quiz!

    Now what I want to do is this:

    c.drawString ("Out of the four circles shown below which is your favorite?",0,0);
    (I'll draw 4 colored circles here, blue, red, pink, and maybe green, idk not important though for them to view and choose)
    c.drawString ("My favorite color is: ",0,10);
    String backgroundColor;
    backgroundColor = c.readLine();

    My problem begins here. I'm using if statements to decide on the color. If it was two colors it would be fine. For example, lets say I only had two colors, blue and red. I would do:

    if (color.equalsIgnoreCase ("blue"))
    {
    c.setColor (Color.blue);
    }
    else
    {
    c.setColor (Color.red);
    }


    My problem is, if I want four colors, how do I do that?
    I want it to be a variety for the class to choose, not just an option between two colors.

    I was thinking maybe if I had sets of two colors with numbers on them and they chose a number.
    After the number they're given the option of the two colors.

    If that makes any sense at all.

    Anyways, if there's a method of allowing 4 possibilities, please let me know, thank you!
    (I've been only coding for a few weeks and by coding I mean c.drawOval, so the more help the better! )

    ---------- Post added at 02:42 PM ---------- Previous post was at 02:26 PM ----------

    Never mind you can remove this topic, my friend helped me on his gaming forums


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: If statement help

    Hi DarkPrince
    Please see the announcements page for the use of code tags as well as other useful forum tips.

    Never mind you can remove this topic, my friend helped me on his gaming forums
    The link above also has information on marking the thread as solved.

Similar Threads

  1. if....else statement
    By Appu14 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: September 2nd, 2012, 06:35 AM
  2. Need help with if statement.
    By dreamer in forum Loops & Control Statements
    Replies: 2
    Last Post: May 30th, 2012, 02:27 PM
  3. If statement help
    By Legion of Daughters in forum Loops & Control Statements
    Replies: 12
    Last Post: September 6th, 2011, 08:25 AM
  4. If Statement
    By Shyamz1 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 26th, 2010, 12:57 PM
  5. If-Else Statement help
    By SnowCrashed in forum Loops & Control Statements
    Replies: 5
    Last Post: February 9th, 2010, 07:57 PM