This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java 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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Graphic Events" Watch "Graphic Events" New topic
Author

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
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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


[Jess in Action][AskingGoodQuestions]
Jacquie Barker
author
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
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Swing / JFC / AWT forum...
[ October 16, 2003: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Graphic Events