Hi I'm developing a SWT Java application. I have created 2 classes: the first contains SWT package where I will run the application and the second is extended for thread. I'm trying to modify the label in the thread while application is running. This is the code where is decleared the label:
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
public class LogoQuiz {
protected Shell shell = new Shell();
public static Label lblNewLabel;
Thread t1 = new Time();
/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
LogoQuiz win1 = new LogoQuiz();
win1.open();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() {
shell.setSize(450, 300);
shell.setText("SWT Application");
Button btnNewButton = new Button(shell, SWT.NONE);
btnNewButton.setBounds(91, 100, 75, 25);
btnNewButton.setText("New Button");
lblNewLabel = new Label(shell, SWT.NONE);
lblNewLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
t1.start();
}
});
lblNewLabel.setBounds(235, 169, 127, 53);
lblNewLabel.setText("New Label");
}
}
And there the code with the thread:
public class time extends Threads {
public void run () {
LogoQuiz.lblNewLabel.setText("Done");
}
}
So, when I run the application and I click on the label twice, it says: "SWTException". I'm developing with Eclipse. Could anyone help me to solve this exception, please? Thanks so much! Sorry for my bad English!