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

+3

Simple help for java lovers

I can't find a simple condition to open frame after 20sec https://code.sololearn.com/cmpwWnQ4N9iQ/?ref=app

3/31/2020 4:35:38 PM

Nebojsa Barac

7 Answers

New Answer

+3

https://code.sololearn.com/cmpwWnQ4N9iQ/?ref=app

+3

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

+3

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

+2

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

+1

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);

+1

About Timer/TimerTask: https://www.baeldung.com/java-timer-and-timertask

0

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); } }