Results 1 to 6 of 6
  1. #1
    JBad is offline Member
    Join Date
    Apr 2014
    Posts
    4
    Rep Power
    0

    Default Code to get Mouse Location (Mouse X & Y coordinates) and display it?!?!? HELP

    I need a complete code and all the correct imports to get Mouse Location (Mouse X & Y coordinates) and display it... Help anyone please. needed ASAP.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,105
    Rep Power
    6

    Default Re: Code to get Mouse Location (Mouse X & Y coordinates) and display it?!?!? HELP

    Well good luck Googling for it. If you want help writing the code yourself after you took a stab at it yourself first, feel free to come back.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    JBad is offline Member
    Join Date
    Apr 2014
    Posts
    4
    Rep Power
    0

    Default Re: Code to get Mouse Location (Mouse X & Y coordinates) and display it?!?!? HELP

    i had some just didn't post it. i've been googling it and piecing together some things!

    import java.awt.*;


    public class Mouseget {

    public static void main (String[] args){
    java.awt.MouseInfo.getPointerInfo();
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

    //finds size end of the screen
    int xscreen = (dim.width);
    int yscreen = (dim.height);

    //these are what the current <span class="highlight">coordinates</span> of the <span class="highlight">mouse</span> are
    int currentx;
    int currenty;

    //this is what the <span class="highlight">mouse</span> changes to
    int x;
    int y;

    //this is to make the loop think it is not infinite...
    int loop = 20;

    //setting the location for the start of the program
    Point p = MouseInfo.getPointerInfo().getLocation();
    currentx = p.x;
    currenty = p.y;



    /*Mouse loop for location*/
    do
    {

    //this gets the x and y and displays them
    Point r = MouseInfo.getPointerInfo().getLocation();
    x = r.x; //x variable of the <span class="highlight">mouse</span> location
    y = r.y; //y variable of the <span class="highlight">mouse</span> location

    can you assist me now?!?

  4. #4
    JBad is offline Member
    Join Date
    Apr 2014
    Posts
    4
    Rep Power
    0

    Default Re: Code to get Mouse Location (Mouse X & Y coordinates) and display it?!?!? HELP

    here is exactly what i need it to do....

    giving that the variable button is a reference to a JButton object. I need the code that will register this object onto a mouse event. so that when i click the button, the X & Y location of the mouse pointer will be displayed on the DOS screen.

  5. #5
    JBad is offline Member
    Join Date
    Apr 2014
    Posts
    4
    Rep Power
    0

    Default Re: Code to get Mouse Location (Mouse X & Y coordinates) and display it?!?!? HELP

    some imports i think i might need after some further research

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,786
    Rep Power
    5

    Default Re: Code to get Mouse Location (Mouse X & Y coordinates) and display it?!?!? HELP

    You do realize that when you "click" on the button, the mouse will be "inside" the button. And exactly why do you want to do this?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. getting mouse location on scroll panes contents
    By yemista in forum AWT / Swing
    Replies: 1
    Last Post: 05-12-2012, 08:24 AM
  2. Location of Mouse/JRadioButton Problem
    By PorgrammingNoob117 in forum AWT / Swing
    Replies: 3
    Last Post: 05-10-2011, 10:01 PM
  3. How do you set the mouse curser location?
    By noobgrammer in forum New To Java
    Replies: 1
    Last Post: 07-20-2010, 01:44 AM
  4. Replies: 7
    Last Post: 04-10-2010, 07:07 PM
  5. Getting mouse coordinates
    By nishant.4545 in forum Advanced Java
    Replies: 3
    Last Post: 07-20-2009, 11:28 PM

Tags for this Thread

Posting Permissions

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