Simply, I have two classes, A GUI class which has a button both for stopping and running the other class/thread which is for getting the text content from clipboard and paste it to a text file. But no matter what I tried (such as using swingworker) I couldn't achive my goal. That code can start the thread but freezes the GUI. I tried using SwingWorker, but failed. Please show me a solution.
class GUI
{
Thread a = null;
JButton onOffButton;
onOffButt.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent arg0)
{
if (a == null)
{
isOn = true;
onOffButt.setText("on");
onOffButt.setBackground(Color.green);
a = new Thread(new TextHandler());
a.start();
}
else
{
isOn = false;
onOffButt.setText("off");
onOffButt.setBackground(Color.red);
a.interrupt();
a = null;
}
}
});
}
class TextHandler() extends Thread
{
run()
{
for(;;)
{
// getClipboardContent();
// evaluate
// paste
}
}
}