Thursday, 15 July 2010

Issue with multithreading in java -



Issue with multithreading in java -

i facing problem in thread .here code

private void custombrightactionperformed(java.awt.event.actionevent evt) { creed = new thread() { public void run() { final jframe jfmae = new jframe("set brightness"); jlabel jla = new jlabel("!@#$"); jfmae.add(jla, borderlayout.center); jfmae.setsize(180, 180); jfmae.addmouselistener(new mymos()); jfmae.addwindowlistener(new windowadapter() { public void windowclosing(windowevent windowevent) { jfmae.dispose(); } }); jfmae.setvisible(true); } }; creed.start(); } class mymos extends mouseadapter { public void mousepressed(java.awt.event.mouseevent evt) { seek { creed.sleep(3000); } grab (interruptedexception e) { } bigh2mousepressed(evt); } private void bigh2mousepressed(java.awt.event.mouseevent evt) { system.out.println("dsds"); } }

custombrightactionperformed

is method of class deals action event , mymos inner class .the problem sleeping creed thread main thread sleeping 3 seconds.why ?

you invoking sleep() on main thread,

sleep() static method using thread's instance (creed) phone call discouraged, sleeps thread in method beingness called

if want pause creed thread need execute thread.sleep() run() method

java multithreading swing thread-sleep

No comments:

Post a Comment