标签云

微信群

扫码加入我们

WeChat QR Code

Hey i just need a question answered...How would i make the following code not freeze my whole JFrame?try {Thread.sleep(Integer.parseInt(delayField.getText()) * 1000);System.out.println("Hello!");} catch(InterruptedException ex) {Thread.currentThread().interrupt();}


thanks that worked :D

2019年04月20日15分26秒

Since JTextField#getText is not thread-safe, you shouldn't be calling that method from another thread then the EDT

2019年04月20日15分26秒

Robin, yup didn't think about that while postin :(... a synchronized method can be used to get the text.. will there be any side affect of that?

2019年04月19日15分26秒

I would retrieve the text outside of that thread, and simply pass it in there. And simply for delay, I would ditch the thread completely and use a Timer as suggested by Marko Topolnik

2019年04月20日15分26秒

Thanks Robin for enlighting me .. I am updating the answer accorind to your advice

2019年04月20日15分26秒