java - Stop thread/object working using jcheckbox -
i have thread class
import java.awt.toolkit; import java.awt.datatransfer.clipboard; import java.awt.datatransfer.clipboardowner; import java.awt.datatransfer.dataflavor; import java.awt.datatransfer.transferable; public class boardlistener extends thread implements clipboardowner { clipboard sysclip = toolkit.getdefaulttoolkit().getsystemclipboard(); @override public void run() { transferable trans = sysclip.getcontents(this); regainownership(trans); system.out.println("listening board..."); while(!isinterrupted()){ } } @override public void lostownership(clipboard c, transferable t) { seek { this.sleep(50); } grab (exception e) { system.out.println("exception: " + e); } transferable contents = sysclip.getcontents(this); processcontents(contents); regainownership(contents); } void processcontents(transferable t) { seek { system.out.println("processing: " + (string)t.gettransferdata(dataflavor.stringflavor)); } grab (exception ex) { ex.printstacktrace(); } } void regainownership(transferable t) { sysclip.setcontents(t, this); } }
in main() create object , object.start()
boardlistener b = new boardlistener(); b.start();
but need somehow using jcheckbox stop/start working object (stop clipboard monitoring). tried b.interupt(); doesn't work, tried setting flag in run while loop, doesn't help.
java multithreading
No comments:
Post a Comment