import org.eclipse.jface.window.ApplicationWindow; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; public class Main extends ApplicationWindow { public Main() { super(null); createActions(); addToolBar(SWT.FLAT | SWT.WRAP); addMenuBar(); addStatusLine(); } @Override protected Control createContents(Composite parent) { Composite container = new Composite(parent, SWT.NONE); Button button = new Button(container, SWT.NONE); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { System.out.println("クリックされました"); Shell shell = Main.this.getShell(); MessageBox messageBox = new MessageBox( shell, SWT.YES | SWT.NO ); messageBox.setMessage("YESかNOを選択してください"); messageBox.setText("メッセージ"); int result = messageBox.open(); if( result == SWT.YES ) { System.out.println("YESがクリックされました"); } if( result == SWT.NO ) { System.out.println("NOがクリックされました"); } } }); button.setBounds(55, 35, 75, 25); button.setText("実行"); return container; } private void createActions() { // Create the actions } public static void main(String args[]) { try { Main window = new Main(); window.setBlockOnOpen(true); window.open(); Display.getCurrent().dispose(); } catch (Exception e) { e.printStackTrace(); } } @Override protected void configureShell(Shell newShell) { super.configureShell(newShell); newShell.setText("New Application"); } @Override protected Point getInitialSize() { return new Point(450, 300); } }