aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Component movement from one (x,y)location to another (x,y)location within given time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Component movement from one (x,y)location to another (x,y)location within given time" Watch "Component movement from one (x,y)location to another (x,y)location within given time" New topic
Author

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

Santhosh Raj
Greenhorn

Joined: Mar 08, 2012
Posts: 25
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

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: Oct 27, 2005
Posts: 19761
    
  20

All I will say at this moment is: check out javax.swing.Timer and Component.setLocation.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Santhosh Raj
Greenhorn

Joined: Mar 08, 2012
Posts: 25
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

Joined: Jun 09, 2003
Posts: 4632
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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Component movement from one (x,y)location to another (x,y)location within given time