Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Udara Amarasinghe
Ranch Hand
Posts: 109
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How is a Graphical object move on the Screen by using JButton until the button release.

 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48363
56
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved it with help of Campbell Ritchie and Maneesh Godbole comments.
This is the solved code.

 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done It is far better to solve the problem yourself than be told a solution because you will remember the answer better.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic