I am using Swing with JDK1.7 and I want to achieve very simple task. I want to open a Frame within seperate Thread on one Button Click. For this i have designed a class called TestThread.
public class TestThread implements Runnable {
public TestThread() {
super();
}
private int target = 100;
public void setTarget(int target) {
this.target = target;
}
public int getTarget() {
return target;
}
@Override
public void run() {
setFrame();
}
public void setFrame() {
JFrame frame = new JFrame("Test");
frame.setVisible(true);
}
}
and on button click one new thread is created and launched with ProgressMonitor component. Now the problem is after open Frame progressMonitor does not closed. It continues runnning forever. I found launcher thread is not getting closed that's why progressMonitor is going on.
Can someone tell me what's wrong with this code.
private void jButton_actionPerformed(ActionEvent e) {
BaseApp.mode = irisApp.mode;
BaseApp.getInstance().setUser(irisApp.getUser());
TestThread test = new TestThread();
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
progressDialog = new ProgressMonitor(this,
"Please wait while system is loading",null, 0, test.getTarget());
progressDialog.setProgress(0);
corpActivityMonitor.setDelay(0);
corpActivityMonitor.start();
Thread thread = new Thread(test);
thread.start();
jButtonCorporation.requestFocus();
}
}
}