| | |
how to use java.util.Timer;
![]() |
•
•
Join Date: Apr 2007
Posts: 40
Reputation:
Solved Threads: 0
hi its me again.. curious thingking about how to control a timer statements per clock tick processes with if else statement
i would like to perform this operations like;
clock.start();
if(clocktime == 1)
System.out.println("Hi");
else if(clocktime == 2)
System.out.println("Hellow");
clock.stop();
i know this program is an error because of incompatible types so can you give me some suggestions and comments about how to perform or code it in a right way..
can u give me some codes regarding to the question
i would like to perform this operations like;
clock.start();
if(clocktime == 1)
System.out.println("Hi");
else if(clocktime == 2)
System.out.println("Hellow");
clock.stop();
i know this program is an error because of incompatible types so can you give me some suggestions and comments about how to perform or code it in a right way..
can u give me some codes regarding to the question
•
•
Join Date: Aug 2008
Posts: 5
Reputation:
Solved Threads: 0
Try somthing like this:
package com.mine.test;
import java.util.Calendar;
import java.util.Timer;
public class Initiater {
/**
* @param args
*/
public static void main(String[] args) {
Timer clock = new Timer();
for(int i=0;i<2;++i)
clock.scheduleAtFixedRate(new MyTimerTask(clock,i),Calendar.getInstance().getTime(),500);
}
}package com.mine.test;
import java.util.Timer;
import java.util.TimerTask;
public class MyTimerTask extends TimerTask {
private int counter = 0;
private Timer timer = null;
public MyTimerTask(Timer timer,int counter) {
this.timer = timer;
this.counter = counter;
}
@Override
public void run() {
switch(counter) {
case 0:
System.out.println("Hello");
break;
case 1:
System.out.println("Hellow");
this.timer.cancel();
}
}
} Last edited by nsisupalan; Aug 30th, 2008 at 11:02 am.
![]() |
Similar Threads
- displaying time (Java)
- Automatic mail using jsp and javamail (JSP)
- Java Game Characteristics (Java)
- Timer Component in JAVA (Java)
- Java tutor needed BADLY (Java)
- Basketball timer help needed (Java)
- I lack focus... (Java)
- Stop Watch (Java)
Other Threads in the Java Forum
- Previous Thread: hibernate.hbm.xml
- Next Thread: how to insert password in cookies??
| Thread Tools | Search this Thread |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class client code compile compiler component database developmenthelp eclipse error fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html ide image input integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loop loops mac main map method methods mobile myregfun netbeans newbie notdisplaying number online page print problem program programming project qt recursion scanner screen server set singleton size sms sort spamblocker sql string swing system template textfields threads time title tree tutorial-sample update variablebinding windows working xor





