Solved

Java MouseReleased

Posted on 2000-02-29
1
872 Views
Last Modified: 2012-06-21
When i release the mouse and get the co-ordinates of where the mouse has being released, e.getX(), e.getY(). it tells me that the position of my cursor is at aroung the top left hand corner of my screen, when in fact it is in the middle of the screen and no where near the co-ordinates it tells me its at, how can i solve this problem of the getting wrong position of my cursor, or any ideas as to what is making it hapen like this??
0
Comment
Question by:j_baxter99
1 Comment
 

Accepted Solution

by:
davidmorand earned 50 total points
ID: 2569137
The x and y position you get are from the component where you handle the mouseReleased event.

So if you handle it on a button and you click on the upper left corner of the button you will get (0,0).

You need to translate those coordinates to screen coordinates using the position of your component as you reference.

so if you have a JWindow at position (100,100) in the screen and you release the mouse at position (50,50) in the JWindow then your cursor is at (150, 150) in the screen!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now