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

Thread: Add MouseClickEvent for a X/Y-Coordinate (JFrame)

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Add MouseClickEvent for a X/Y-Coordinate (JFrame)

    Hello Everyone

    I Google'd for a solution to my problem, but I couldnt find anything

    I want to add a MouseClickEvent for my GUI, but only for a small part of my JFrame.

    I made it work with a Invisible Button, but for several reasons I'd like to add the Event in the JFrame.

    Is there a Method with which I can define a range from the X/Y-Coordinates of the JFrame?

    Sorry for my imperfect english

    Thx
    Student_27


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,587
    Thanks
    45
    Thanked 1,956 Times in 1,930 Posts

    Default Re: Add MouseClickEvent for a X/Y-Coordinate (JFrame)

    If you want to have a listener only respond to clicks in a selected area, add some if tests for detecting where the click was done and ignore it if the click is not in the desired area.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Add MouseClickEvent for a X/Y-Coordinate (JFrame)

    Quote Originally Posted by Norm View Post
    If you want to have a listener only respond to clicks in a selected area, add some if tests for detecting where the click was done and ignore it if the click is not in the desired area.
    How do I do this?
    Can you write me some Code as an Example?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,587
    Thanks
    45
    Thanked 1,956 Times in 1,930 Posts

    Default Re: Add MouseClickEvent for a X/Y-Coordinate (JFrame)

    The MouseEvent class has some methods that return the x and y values for the location of the mouse click.
    Get those values and compare them against the bounds of area where the program wants to use the clicks.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 5
    Last Post: February 15th, 2013, 04:01 PM
  2. how to add a JFrame listener for a JPanel
    By netll in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 27th, 2012, 06:54 AM
  3. How Do i add pictures to a jframe?
    By Java Programmer in forum What's Wrong With My Code?
    Replies: 10
    Last Post: January 21st, 2012, 11:34 AM
  4. add jscrollpane to jframe
    By pravinrasal in forum AWT / Java Swing
    Replies: 1
    Last Post: November 14th, 2011, 06:01 AM
  5. Dynamically add a Jpanel to a Jframe
    By Closet_Rambo in forum AWT / Java Swing
    Replies: 6
    Last Post: October 3rd, 2011, 03:51 AM