Ceci est une ancienne révision du document !
Standard Widget Toolkit
-- Création d'une application SWT
Installer au besoin Window Builder Pro dans Eclipse.
- Création d'un projet : Choisir File/New/other/Window Builder/SWT/JFace java Project
- Choisir File/New/other/SWT/Application Window
-- Structure d'une application
public class MainWindow {
protected Shell shell;
/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
MainWindow window = new MainWindow();
window.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 = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");
}
}
-- Mode Design
-- Implémentation du comportement
-- Ajout de listener
- Sélectionner L'option 1, faire apparaître le menu contextuel avec le bouton droit de la souris :
- Choisir add Event Handler/ Selection/ WidgetSelected
btnOption.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
}
});
- Ajouter un membre privé Button activeButton
- Implémenter le code suivant :
@Override
public void widgetSelected(SelectionEvent e) {
activeButton = (Button) e.getSource();
text.setText(activeButton.getText());
}


