How to make a Timer?
java, timer
Solution
Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
System.out.println("Hi!");
}
}, 400);
Problem
I want to make a `Timer` that waits 400 MSc and then goes and prints "hi !" (e.g.). I know how to do that via `javax.swing.Timer` ``` ActionListener action = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("hi!"); } }; ``` plus : ``` timer = new Timer(0, action); timer.setRepeats(false); timer.setInitialDelay(400); timer.start(); ``` but as I know this definitely is not a good way as this kind of `Timer` is for Swing works. how to do that in it's correct way? (without using `Thread.sleep()`)