按钮的监听器的写法:
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
public class MessageBoxDemo {
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("第一个shell窗口");
Button btn = new Button(shell,SWT.NONE);
btn.setText("click me");
btn.setBounds(10, 10, 100, 100);
btn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event){
MessageBox box = new MessageBox(shell, SWT.OK|SWT.CANCEL|SWT.ICON_QUESTION);
box.setText("title");
box.setMessage("Content");
box.open();
// MessageDialog.openConfirm(shell, "hello", "Content");
// MessageDialog.openInformation(shell, "title", "Content");
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}