Results 1 to 1 of 1
Thread: MessageBox Example in SWT
-
MessageBox Example in SWT
Java Code:import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; public class MessageBoxExample { Display display = new Display(); Shell shell = new Shell(display); Button button; public MessageBoxExample() { button = new Button(shell, SWT.PUSH); button.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { MessageBox messageBox = new MessageBox(shell, SWT.ICON_WARNING | SWT.ABORT | SWT.RETRY | SWT.IGNORE); messageBox.setText("Warning"); messageBox.setMessage("Save the changes before exiting?"); int buttonID = messageBox.open(); switch(buttonID) { case SWT.YES: // saves changes ... case SWT.NO: // exits here ... break; case SWT.CANCEL: // does nothing ... } System.out.println(buttonID); } }); button.setText("Click me!"); button.setBounds(0, 0, 100, 30); shell.pack(); shell.open(); //textUser.forceFocus(); // Set up the event loop. while (!shell.isDisposed()) { if (!display.readAndDispatch()) { // If no more entries in event queue display.sleep(); } } display.dispose(); } private void init() { } public static void main(String[] args) { new MessageBoxExample(); } }"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Similar Threads
-
MessageBox example
By Java Tip in forum Java TipReplies: 0Last Post: 03-14-2008, 11:33 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks