This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Graphic Events Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Graphic Events" Watch "Graphic Events" New topic

Graphic Events

Nick Delauney
Ranch Hand

Joined: Sep 28, 2002
Posts: 43
I know how to make graphics with Graphics G and the paint method. If I wanted to make some functionallity in which a user could drag a circle and it some where else on the canvas, how would I go about that. (I.E - like moving a checker peace in yahoo checkers). Any help is apreciated. Thanks.

N.D:"Anything worth having, takes time to get"
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

One classic example of this comes with the J2SDK: see demos/applets/GraphLayout .

[Jess in Action][AskingGoodQuestions]
Jacquie Barker
Ranch Hand

Joined: Dec 20, 2000
Posts: 201
One way to do this is by tracking MouseEvents -- you can determine the (x,y) location of the mouse, compute whether it is "on" or "off" of the circle, and if it is "on", compute where the circle would have moved, then redraw it.

Author of Beginning Java Objects, Beginning C# Objects, and Taming the Technology Tidal Wave
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Swing / JFC / AWT forum...

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: Graphic Events
Similar Threads
super.painComponent(g) not clearing my Jpanel
how to hide the blue line?
java newbee guidance
How to avoid repaint?
Graphic Events