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

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();
		}
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.