I am now studying classes and inheritance in Java. I made a simple rpg game. and Now I try to use the multithreading, but it does not work. I want the output to come out every 30 seconds. "It's been 30 seconds since the game started." like this.. The numbers will grow over time. What should I do? Actually, I can't speak English well and it can be awkward.. I'll wait for your answer. Thank you!
//import java.util.Timer;
import java.util.TimerTask;
public class Timer extends Thread {
int count = 0;
Timer m_timer = new Timer();
TimerTask m_task = new TimerTask() {
public void run() {
count++;
System.out.println("It's been 30 seconds since the game started.");
}
};
m_timer.schedule(m_task, 1000, 1000);
};
Main:
public class Main {
public static void main(String[] args) {
Timer m_timer = new Timer();
m_timer.start();
}
}