I work on jFrame project:
I have jlabel
I want to move it in animation, and then move another jlabel
in other words, I want the first jlabel
to move and then when it finished,the second jlabel
moves.
I've already tried and didn't succeed. I have a function to move one jlabel
and ifIi try to use it on both jlabels, both jlabels move at the same time, and I don't want this to happen.
Can you help me do it, thank you so much.
Here is the function that I have :
public void MoveForPlayer(JLabel PlayerCard)
{
int delay = q;
ActionListener taskPerformer = new ActionListener() {
int count=0;
@Override
public void actionPerformed(ActionEvent evt) {
if(count==20) {
((Timer)evt.getSource()).stop();
}
PlayerCard.setLocation((PlayerCard.getLocation().x-5), PlayerCard.getLocation().y+5);
count++;
}
};
new Timer(delay, taskPerformer).start();
}
You could take a look at something like this example which wraps animation layer around a
GridBagLayout
or someting like this which is based on the Universal Tween EngineThis is a modified version of the first example, which adds the ability to be notified when the animation for a particular layout sequence has finished.
Before you tell me "it's too complicated", understand that animation alone is a complex subject, but when trying to animated components who should be under the control of appropriate layout managers, it becomes even more complicated...
If I understand your question correctly, you want that one JLabel should be moved every second time the timer is run, and a different one should be moved every other time the timer is run. If this is the case, you can use the
count
variable you already have to decide which one to move.For example:
and then...