(Java) Get mouse position coordinates

Source: Internet
Author: User

Recently bored to play new tricks, need to get screen coordinates, before this thing is directly installed someone else's EXE tool, now think of themselves also count the program Ape, write a bar

In fact, it is not difficult, in general, is to create a panel, and then real-time monitoring the position of the mouse to display it

For the position of the mouse can be obtained in MouseEvent E's E.getx () and E.gety () methods, the code is as follows:

public void mousemoved (MouseEvent e) {
int x = E.getx ();
int y = e.gety ();
String s = "Current mouse coordinates: (" + x + "," + y + ")";
MouseMove.lab.setText (s);
}

Then find a place of your own to show it

Because you get the entire screen, you also want to get the screen size and hide the title bar, as follows:

Get screen Size

static Dimension screensize = Toolkit.getdefaulttoolkit (). Getscreensize ();
int width = (int) screensize.getwidth ();
int height = (int) screensize.getheight ();

Hide title bar

Fm.setundecorated (TRUE);

Note here that the statement that hides the title bar is placed before setvisible ()

(Java) Get mouse position coordinates

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.