slimeSkybird
Grünschnabel
Code:
package Test;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;
public class Threads {
public static void main(String[] args)
{
// Shell wird erzeugt und mittig positioniert
// ------------------------------------------
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("Threads");
shell.setSize(200,200);
Monitor pMonitor = display.getPrimaryMonitor();
Rectangle bounds = pMonitor.getBounds();
Rectangle rect = shell.getBounds();
int x = bounds.x + (bounds.width - rect.width) / 2;
int y = bounds.y + (bounds.height - rect.height) / 2;
shell.setLocation(x, y);
// ------------------------------------------
// Shellunterteilung wird erzeugt
// ------------------------------
GridLayout gridLayout1 = new GridLayout();
gridLayout1.numColumns = 1;
shell.setLayout(gridLayout1);
shell.setBackgroundMode(SWT.INHERIT_DEFAULT);
// ------------------------------
//Button fürs Testen
//------------------
Button B_letztenfertig = new Button(shell,SWT.BORDER);
B_letztenfertig.setText("Start");
//------------------
//Listener fürs Fertig markieren
//------------------------------
B_letztenfertig.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
//-----------------------------
new Thread() {
public void run() {
Runnable r = new Runnable(){
public void run(){
//Hier was Threadlastiges
}
};
display.asyncExec(r);
}
}.start();
//-----------------------------
}});
//------------------------------
// Shell wird geöffnet
// -------------------
shell.open();
// -------------------
//--------------------
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
//--------------------
}
}
Hier mal Beispielcode, wie ich vorgehe