Results 1 to 2 of 2
Thread: Java mouse events in gui.
- 12-19-2011, 10:18 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 1
- Rep Power
- 0
Java mouse events in gui.
I fiew days in java and i can't undetstand what here is wrong? why it write me x:0 y:0?

I use netBeans.
Java Code:private void But1MousePressed(java.awt.event.MouseEvent evt) { int aMx = getX(); int aMy = getY(); But1.setText("x:" + aMx + "y:" + aMy); }Last edited by pbrockway2; 12-19-2011 at 10:45 PM.
- 12-19-2011, 10:54 PM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Re: Java mouse events in gui.
You are calling getX() on whatever thing this code is part of. It could very well be a Component at the top left corner of the screen where getX() returns zero. Better to call getX() on the MouseEvent instance if you want to know the position of the mouse.
-----
If you have only been using Java for a few days I would strongly recommend you work through basic Java syntax either from a textbook or something online like Oracle's Tutorial. Graphical user interfaces are complex and coding them in Java is not something that can be explained piecemeal in a forum.
In Java variables and methods start with a lowercase letter. So, but1MousePressed() and but1.
Similar Threads
-
Help with drawing a string using mouse events
By ptuckley in forum AWT / SwingReplies: 2Last Post: 12-14-2010, 11:09 AM -
Help with some basics please (mouse events)
By tigersarehot in forum AWT / SwingReplies: 4Last Post: 04-28-2010, 02:22 AM -
Mouse events, are they best or only way to go?
By dbashby in forum New To JavaReplies: 2Last Post: 04-10-2009, 04:34 PM -
Need help with looping mouse Events.
By busdude in forum New To JavaReplies: 1Last Post: 04-08-2009, 08:25 PM -
Demonstration of mouse events
By Java Tip in forum SWTReplies: 0Last Post: 07-11-2008, 04:45 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks