| | |
how to use java.util.Timer;
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
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 |
Tag cloud for Java
actionlistener android api append apple applet application arguments array arrays automation bi binary bluetooth busy_handler(null) chat class classes clear client code component database draw eclipse ee error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me java javaprojects jmf jni jpanel julia jvm key lego linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie nextline notdisplaying number oracle output print problem program programming project qt recursion repositories robot scanner screen se server set singleton size sms socket sort sql string swing terminal test textfields threads time transfer tree utility windows wrong xor





