Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Component movement from one (x,y)location to another (x,y)location within given time

 
Santhosh Raj
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI All,
I have a requirement where in a JComponent like JButton, JLabel, JTextArea, etc., should me moved from given (x,y) location to another given (x,y) location within a given specific time in milli seconds.
Inputs given are:
1. Start (x,y)
2. End (x,y)
3. Time to travel from start (x,y) to end (x,y)
Say, if i have given the time as 4000ms, the component should travel from start (x,y) to end (x,y) in 4000ms (4 secs).
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I have a requirement...

we won't write it for you, so you need to
post what you've tried and the problems
you have.
 
Rob Spoor
Sheriff
Pie
Posts: 20497
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All I will say at this moment is: check out javax.swing.Timer and Component.setLocation.
 
Santhosh Raj
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for the replies and sorry that I dint post what I have tried on till now.
Here is the piece of code what I am doing right now.




The 'direction' refers to which direction is the component coming from.
For direction, I have done the below calculation so that the component will start from the location which will be set by the below calculations.



I am doing this entire thing in Swing Timer itself but I am not getting the exact calculation.
I mean the component is not coming to the center of the Panel after its transition according to the transition time.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you really need to post a working program that demonstrates the problem.

just have it move from a to b in x time, forget directions.
if you get the first part working OK, then add a direction etc

doing it this way, you might find the problem yourself, but if not, you can
post the code with the info that it worked OK until I added this...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic