+ 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

31st Mar 2020, 4:35 PM
Nebojsa Barac
Nebojsa Barac - avatar
7 odpowiedzi
+ 3
https://code.sololearn.com/cmpwWnQ4N9iQ/?ref=app
2nd Apr 2020, 4:22 PM
Nebojsa Barac
Nebojsa Barac - avatar
+ 3
Now works.. thanks for link Denise first time i see TimerTask..
2nd Apr 2020, 4:23 PM
Nebojsa Barac
Nebojsa Barac - avatar
+ 3
Nebojsa Barac Thanks for sharing your solution with the other Timer.
2nd Apr 2020, 4:48 PM
Denise Roßberg
Denise Roßberg - avatar
+ 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
1st Apr 2020, 7:08 AM
Nebojsa Barac
Nebojsa Barac - avatar
+ 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);
1st Apr 2020, 1:08 PM
Denise Roßberg
Denise Roßberg - avatar
1st Apr 2020, 1:13 PM
Denise Roßberg
Denise Roßberg - avatar
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); } }
1st Apr 2020, 4:00 AM
Raúl