Results 1 to 5 of 5
  1. #1
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Exclamation ActionListener on Graphics

    Greetings,

    Does this exist in java, wherein in a canvass, i set a specific area to be trigger by a mouse click to perform an ActionEvent.

    Thanks,
    Cyril H.
    Every project, package, class, method, variable, syntax, algorithm, etc.
    are registered in my memory bank. Thanks to this thread.

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

    Default

    There is no ActionListener available for images, such as a background image in a JPanel or an ImageIcon in a JLabel since ActionListeners are for components that extend AbstractButton such as menu items and JButtons. But all is not lost since you could simply use a MouseListener for these other components.

  3. #3
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Default

    Ok, but is area mapping considered to trigger an event by MouseListener?
    What I meant, could I implement in image a specific area (x,y,x1,y1) to trigger an event?
    Every project, package, class, method, variable, syntax, algorithm, etc.
    are registered in my memory bank. Thanks to this thread.

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

    Default

    Quote Originally Posted by chyrl View Post
    Ok, but is area mapping considered to trigger an event by MouseListener?
    What I meant, could I implement in image a specific area (x,y,x1,y1) to trigger an event?
    Have you tried it? A mousePressed method will be passed a MouseEvent object that will contain the location of the Point where the mouse was pressed relative to the component being listened. This information can be used in an if block to alter program flow.

  5. #5
    Jcbconway is offline Senior Member
    Join Date
    Sep 2010
    Posts
    109
    Rep Power
    0

    Default

    Yes, if you use the MouseClicked buton, and did used the .getX() and .getY() meathods, you would then know where you pressed. so, by knowing that, you could have a statement checking, weather or not your in the bounds of the image by finding its x,y ranges.

Similar Threads

  1. ActionListener+KeyListener
    By mandelbrot in forum AWT / Swing
    Replies: 5
    Last Post: 09-10-2010, 12:25 AM
  2. Problem Actionlistener
    By Questionmark in forum New To Java
    Replies: 18
    Last Post: 08-07-2010, 12:29 PM
  3. Java actionlistener help
    By justsomeguy in forum AWT / Swing
    Replies: 1
    Last Post: 05-27-2008, 05:42 AM
  4. Demonstrating the ActionListener
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 04-23-2008, 08:20 PM
  5. How to use KeyListener and ActionListener
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 04-23-2008, 08:19 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
  •