swing - How to make a thread not freeze you whole JFrame. JAVA -
hey need question answered... how make following code not freeze whole jframe?
try { thread.sleep(integer.parseint(delayfield.gettext()) * 1000); system.out.println("hello!"); } catch(interruptedexception ex) { thread.currentthread().interrupt(); }
use different thread perform task. if in main ui thread freeze.. example can following
new thread() { @override public void run() { try { thread.sleep(integer.parseint(delayfield.gettext()) * 1000); system.out.println("hello!"); } catch (interruptedexception ex) { thread.currentthread().interrupt(); } } }.start();
update
after wise suggestions of robin , marko updating answer better solution.
actionlistener taskperformer = new actionlistener() { public void actionperformed(actionevent evt) { system.out.println("hello!"); } }; javax.swing.timer t = new javax.swing.timer(integer.parseint(delayfield.gettext()) * 1000, taskperformer); t.setrepeats(false); t.start();
Comments
Post a Comment