This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How is a Graphical object move on the Screen by using JButton. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "How is a Graphical object move on the Screen by using JButton." Watch "How is a Graphical object move on the Screen by using JButton." New topic
Author

How is a Graphical object move on the Screen by using JButton.

Udara Amarasinghe
Ranch Hand

Joined: Aug 17, 2009
Posts: 109

How is a Graphical object move on the Screen by using JButton until the button release.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32654
    
    4
Welcome to JavaRanch

We don't simply give out such answers, but if you would show us what you have so far, we shall be happy to comment on it.
By the way: it sounds very unusual behaviour for a button to start motion, then stop it when the mouse is released.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 8435

What you have in mind is not possible with the action listener.
An action performed will not be fired until a successful click.
Click=press+release.

Check out the mouse listeners.
Like Campbell said, try out various scenarios on your own. If you run into a problem, show us your code, and we will be more than happy to help you figure out what is going wrong.
Best of luck.


[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 8435

Udara,

Please read my previous reply carefully why it is not possible with an action listener.
In case you do not know about mouse listeners, here is a tutorial
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32654
    
    4
Maneesh has already told you, you need a different Listener. You would also need a Timer (at the very least) or a new Thread to move the object. Have a look through the tutorial you have been told about.
Udara Amarasinghe
Ranch Hand

Joined: Aug 17, 2009
Posts: 109

I solved it with help of Campbell Ritchie and Maneesh Godbole comments.
This is the solved code.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32654
    
    4
Well done It is far better to solve the problem yourself than be told a solution because you will remember the answer better.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How is a Graphical object move on the Screen by using JButton.
 
Similar Threads
Using a custom renderer for JComboBox
Can I Use JLayeredPane
is it possible to design your own background 4 jbuttons
painting custom components without extending jcomponent
Problem when repainting rectangles