Results 1 to 9 of 9
  1. #1
    Joshr is offline Member
    Join Date
    Oct 2008
    Posts
    2
    Rep Power
    0

    Default if else statements and using images

    I am looking for a way to ask a user to choose between two images and upon their answer the appropriate image appears. It is for a class I am taking and we are suppose to do this using an if else statement. The suggestion that I have been given is to declare a static instance variable at the beginning of the class. I was wondering if anyone has any other suggestions on how to do this?

  2. #2
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    What do you think? Make a start and see how far you come. Than ask again.
    I die a little on the inside...
    Every time I get shot.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,463
    Rep Power
    25

    Default

    Break the problem down into separate steps.
    1) Ask a question and get a response from a user.
    2) display an image

    You can use a static variable but it is NOT needed.
    Design the program first, then decide how to implement it.

  4. #4
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    Why static anyways?
    I die a little on the inside...
    Every time I get shot.

  5. #5
    Joshr is offline Member
    Join Date
    Oct 2008
    Posts
    2
    Rep Power
    0

    Default

    The static variable was just the suggestion given by the instructor. I thought that it was because you can only use static variables with static methods. However after doing some reading and messing around with this last night I think I have figured out a way to do this. The problem I am having now is when I attempt to assign the graphic to a variable I am getting an illegal start of expression error. I am troubleshooting this now to the best of my ability however i have only been doing this for like 6 weeks, so it is still incredibly new to me.

  6. #6
    spider is offline Member
    Join Date
    Oct 2008
    Posts
    5
    Rep Power
    0

    Default

    Can u give more information on the error. Any stack trace ?

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,463
    Rep Power
    25

    Default

    When you get an error, copy and post the full text here. There is info in it that will help solve the problem.

  8. #8
    xdope is offline Member
    Join Date
    Oct 2008
    Posts
    10
    Rep Power
    0

    Default

    maybe its a user error

    type the whole problem so we can see the error

  9. #9
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    And, of course, post your code when posting the stack trace... (highlight the given lines)
    I die a little on the inside...
    Every time I get shot.

Similar Threads

  1. Need help - using algorithm statements
    By javanewbie in forum New To Java
    Replies: 2
    Last Post: 07-23-2008, 11:20 AM
  2. avoiding if statements
    By valoyivd in forum New To Java
    Replies: 1
    Last Post: 04-02-2008, 09:08 AM
  3. Help with actionPerformed Statements
    By wco5002 in forum New To Java
    Replies: 8
    Last Post: 03-26-2008, 04:02 AM
  4. Help with if else statements
    By zoe in forum New To Java
    Replies: 1
    Last Post: 07-24-2007, 07:56 PM

Posting Permissions

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