Results 1 to 2 of 2
Thread: Timer Problem
- 10-20-2011, 09:58 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 21
- Rep Power
- 0
Timer Problem
Hi every one,
in order to make a method to make a nice transition to any swing item like JPanel or JButton or others, i made the following method :
public static void MoveTo(final Container Cnt,final int fX,final int fY,final int Slow) {
MyActionListener = new ActionListener()
{
int initialX=Cnt.getX();
int initialY=Cnt.getY();
int DeltaX=fX-initialX;
int DeltaY=fY-initialY;
public void actionPerformed(ActionEvent actionEvent) {
Cnt.setLocation(initialX + (int)(DeltaX*Math.sin(Counter*Math.PI/(2*Slow))) , initialY + (int)(DeltaY*Math.sin(Counter*Math.PI/(2*Slow))) );
Counter++; if (Counter>=Slow) { //Cnt.setLocation(fX,fY);
Counter=0;
MyTimer.stop();
}
}
};
MyTimer = new javax.swing.Timer(0, MyActionListener); //0 milliSeconds as Delay ....
MyTimer.start();
}
But when i use it i face a Crazy problem :
if i call it and wait it to complete its motion : No Problem...
BUT if the user calls it and BEFORE ending its motion the user again calls it, a CRAZY motion occurs....
i have an idea of the problem reason : i call it again then the Conter and may be Mytimer and others are double-used....
But i don't have an idea about any SOLUTION ....
Someone has a solution or other idea ...
Many thanksLast edited by ellias2007; 10-20-2011 at 10:25 PM.
-
Re: Timer Problem
You've posted 15 times -- please use code tags so we can read your code.
I suggest that you create and post a small compilable and runnable program that shows your problem, again with code tags. Also, don't use a timer delay of 0 as that's unrealistic. Experiment with different values, but not 0.
Similar Threads
-
problem using an action listener and swing timer on a jpanel
By kswiss in forum AWT / SwingReplies: 10Last Post: 04-02-2011, 11:06 PM -
Pac-Man in NetBeans- a Timer and jLabel/jPannel problem
By PR0PHET in forum New To JavaReplies: 15Last Post: 11-15-2010, 08:29 PM -
How to cancel an individual timer in spite of canceling whole timer
By Java Tip in forum java.utilReplies: 0Last Post: 04-04-2008, 02:46 PM -
Problem with timer in java
By paul in forum Advanced JavaReplies: 3Last Post: 07-26-2007, 10:18 AM -
problem with timer
By Marcus in forum Advanced JavaReplies: 2Last Post: 07-01-2007, 05:13 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks