I need to move an object, then it stays still, then move it back, stays still. And move it again etc., i times. The code I have is below, which uses nested swing timers. How to get the desired behavior? Is nested timers the right approach? What should I do?
if (e.getSource()==go){ if (!timer.isRunning()) { timer.start(); } for(int i = 0; i < 1; i++){ int timeA = 9000*i; Timer timermy1A = new Timer(0, new ActionListener() { public void actionPerformed(ActionEvent evt) { Timer timermy1Z = new Timer(0, new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("Hello00"); signstay1 = -0.5f; staybool1 = false; staybool1B = false; } }); timermy1Z.start(); timermy1Z.setRepeats(false); Timer timermy1B = new Timer(3000, new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("Hello3000B"); if(imy1 == 1){ signstay1 = -1.0f; } staybool1 = false; staybool1B = false; Timer timermy1C = new Timer(3000, new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("Hello6000CCCCCC"); staybool1 = true; staybool1B = true; } }); timermy1C.start(); timermy1C.setRepeats(false); } }); timermy1B.start(); timermy1B.setRepeats(false); imy1++; } }); timermy1A.start(); timermy1A.setRepeats(false); } } |
Free forum by Nabble | Edit this page |