11-Dialog - Dialog Boxes 1 Dialog Boxes Dialog boxes are...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
1 1 Dialog Boxes 2 Dialog Boxes Dialog boxes are pop-up windows that give information to or get information from the user A modal dialog box will not let the user interact with the remaining windows of the application until he or she deals with the dialog box Used when information is needed from the user before the application can proceed A modeless dialog box lets the user enter information in both the dialog box and the remaining windows of the application
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 3 Dialog Boxes The JOptionPane class Modal dialogs with just a single message No special dialog box code Custom-designed dialog boxes using JDialog Standard dialogs for file and color selection JFileChooser JColorChooser 4 JOptionPane Dialogs The JOptionPane class has four static methods to show simple dialogs showMessageDialog Show a message and wait for the user to click OK showConfirmDialog Show a message and get a confirmation (like OK / Cancel) showOptionDialog Show a message and get a user option from a set of options showInputDialog Show a message and get one line of user input Dialog components An icon A message One or more option buttons
Background image of page 2
3 5 Dialog Components An icon ERROR_MESSAGE INFORMATION_MESSAGE WARNING_MESSAGE QUESTION_MESSAGE PLAIN_MESSAGE You can supply your own icon A message, which can be any of the following: String Draw the string Icon Show the icon Component Show the component Object [ ] Show all objects in the array, stacked on top of each other Any other object Apply toString and show the string 6 Dialog Components showMessageDialog OK button showInputDialog OK and Cancel buttons showConfirmDialog DEFAULT_OPTION YES_NO_OPTION YES_NO_CANCEL_OPTION OK_CANCEL_OPTION
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 7 Dialog Components showOptionDialog You can specify an arbitrary set of options Supply an array of objects for the options, each array element rendered as String make a button with the string as label Icon make a button with the icon as label Component show the component Any other object apply toString and make a button with the resulting string as label 8 Returning Values showMessageDialog None showConfirmDialog An integer representing the chosen option showOptionDialog An integer representing the chosen option showInputDialog The string that the user supplied or selected
Background image of page 4
9 Steps for Using JOptionPane Dialogs Choose the dialog type (message, confirmation, option, or input) Choose the icon (error, information, warning, question, none, or custom) Choose the message (string, icon, custom component, or a stack of them) For a confirmation dialog, choose the option type (default, Yes/No, Yes/No/Cancel, or OK/Cancel) For an option dialog, choose the options (strings, icons, or custom components) and the default option For an input dialog, choose between a text field and a combo box Locate the appropriate method to show the JOptionPane 10 Example int selection = JOptionPane.showConfirmDialog(parent, “Message”, “Title”, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); ... if (selection == JOptionPane.OK_OPTION)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 31

11-Dialog - Dialog Boxes 1 Dialog Boxes Dialog boxes are...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online