Simple help for java lovers | Sololearn: Learn to code for FREE!


Simple help for java lovers

I can't find a simple condition to open frame after 20sec

3/31/2020 4:35:38 PM

Nebojsa Barac

7 Answers

New Answer



Now works.. thanks for link Denise first time i see TimerTask..


Nebojsa Barac Thanks for sharing your solution with the other Timer.


I work on some task and i need to use timer. Secund option is countdown where timer start on 20sec and when is 0 need to stop.. and open frame.. but tnx for this


Do you really have to use import javax.swing.Timer; ? There exist also java.util.Timer; static JFrame f; static long time = 20000; in main: f = new Frame(); f.setSize(300, 400); TimerTask task = new TimerTask() { @Override public void run(){ f.setVisible(true); } }; Timer timer = new Timer(); timer.shedule(task, time);


About Timer/TimerTask:


Try this (in an IDE such as Eclipse): import javax.swing.JFrame; public class Main { public static void main(String[] args) { try { Thread.sleep(20000); //This causes that this thread waits for 20s } catch (InterruptedException e) { e.printStackTrace(); } JFrame f = new JFrame(); f.setBounds(100, 100, 600, 400); f.setVisible(true); } }