Results 1 to 11 of 11
  1. #1
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

    Default How do I check if user clicks on an image?

    I have three images called "Play" , "Instruction" , "Quit". I need to see if the user clicks on one of those and go from there. But i do not even know where to begin. So my questions are:

    How do I check for mouse clicked?
    How do i check if an image is clicked?

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

  3. #3
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Location
    Rizal Province, Philippiines
    Posts
    167
    Rep Power
    0

    Default

    where's your code

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    Add your image to a JButton and use an ActionListener. The tutorial also has a section on "How to Write an ActionListener".

  5. #5
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

    Default

    I can't add to Jbutton because for some reason it wont show up on the scree.

    Maybe because i am doing the jbuttons on a different screen

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by rajkobie View Post
    I can't add to Jbutton because for some reason it wont show up on the scree.

    Maybe because i am doing the jbuttons on a different screen
    I don't know how you would expect us to know what you're doing wrong based on this scant description. If you still need our help, you'll need to give give more information -- enough that would allow us to answer your question.

  7. #7
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    Quote Originally Posted by rajkobie View Post
    I can't add to Jbutton because for some reason it wont show up on the scree.

    Maybe because i am doing the jbuttons on a different screen

    Creating a JButton wont display it automatically, you'll have to display it yourself. To save yourself the complexity of learning that right now, I'd suggest you download an IDE like Netbeans or Eclipse and create your GUI in there so you can focus on the logic.

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default

    Visual designer + coding newbie = pain

    Kevin's already provided a link to one page of the Swing tutorials. From there it's a simple matter to find the start page of those tutorials and go through the topics.

    db

  9. #9
    rajkobie is offline Member
    Join Date
    Nov 2010
    Posts
    54
    Rep Power
    0

    Default

    I am sorry, I am doing the best of my ability explaining. I cannot post my code in a public forum since this is a school project. I am trying to collect vague answers develop the solution on my own. That way i actually learn it instead of someone giving it to me.

    Geez.

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by rajkobie View Post
    I am sorry, I am doing the best of my ability explaining. I cannot post my code in a public forum since this is a school project. I am trying to collect vague answers develop the solution on my own. That way i actually learn it instead of someone giving it to me.

    But this question:
    I can't add to Jbutton because for some reason it wont show up on the scree.

    Maybe because i am doing the jbuttons on a different screen
    Is a specific request to help figure out what you're doing wrong in your code, and quite simply without your code we haven't a clue.
    Last edited by Fubarable; 05-04-2011 at 04:48 AM.

  11. #11
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    That way i actually learn it instead of someone giving it to me.
    And that is exactly what I did. I suggested that you need to use a JButton with an ActionListener. You have a link to a tutorial. I suggested a section to read. So now its up to you to do the reading and come up with your own solution. The example programs show how to add buttons to the screen.

    We can't possibly guess what you might be doing wrong. We are not mind readers. So we can't offer futher help since you aren't willing to post code.

    It is your job to compare your code with the working examples from the tutorial to see what you are doing wrong.

Similar Threads

  1. saving image to user machine
    By nn12 in forum New To Java
    Replies: 6
    Last Post: 03-10-2011, 11:02 AM
  2. Responding to clicks outside a window
    By bayan in forum New To Java
    Replies: 6
    Last Post: 06-14-2010, 04:51 PM
  3. The trouble with handling the button clicks
    By Borneq in forum New To Java
    Replies: 3
    Last Post: 01-10-2010, 02:57 PM
  4. How to swap to images on clicks
    By ntagrafix in forum AWT / Swing
    Replies: 2
    Last Post: 12-03-2009, 08:13 PM
  5. Replies: 2
    Last Post: 04-16-2008, 12:18 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
  •