dialog boxes

dialog boxes - CSc 2700: Lecture # 19 Dialog Boxes November...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: CSc 2700: Lecture # 19 Dialog Boxes November 4, 2008 1 Introduction A dialog box is a pop-up window that is used for both input and output. Dialog boxes provide specific but simple functionality that could otherwise be built from labels, buttons, and listeners but with more effort. However, dialog boxes effect input and output without your having to deal with events and listeners. Swings JOptionPane class provides a few useful dialog boxes including: Message Dialog Box, Confirmation Dialog Box, and Input Dialog Box. Figure 1: A Dialog Box 2 The Message Dialog Box A Message Dialog Box displays a message and nothing else. Figure 18.18 shows a Message Dialog Box. To incorporate a Message Dialog Box into an application, invoke one of the static methods of JOptionPane: 1 public static void showMessageDialog( Component parent, Object mes- sage); public static void showMessageDialog( Component parent, Object mes- sage, String title, int messageType); public static void showMessageDialog( Component parent, Object mes- sage, String title, int messageType, Icon icon); such that parent is the parent component of the dialog box. Use null to signify the default component. message is the object that the dialog box displays. Technically, message can be any object, a button, a label, a text field. However, for the most part, message is a String. title is the text displayed in the title bar. messageType is one of the following constants: JOptionPane.ERROR_MESSAGE (numerical value: 0) JOptionPane.INFORMATION_MESSAGE (numerical value: 1) JOptionPane.PLAIN_MESSAGE (numerical value:-1) JOptionPane.WARNING_MESSAGE (numerical value: 2) JOptionPane.QUESTION_MESSAGE (numerical value: 3) icon is an image that can be displayed on the dialog box. The Message Dialog Box of Figure 1 is the result of the following statement: JOptionPane.showMessageDialog(null,"Password Incorrect", "WeSellEverything.com",JOptionPane.WARNING_MESSAGE ); The icon displayed by the message is Javas standard icon that is displayed when messageType is passed JOptionPane.ERROR MESSAGE. Whenever messageType is passed one of the JOptionPane constants, the system uses a standard icon in the dialog box. These are shown in Figure 2 2 JOptionPane.INFORMATION_MESSAGE JOptionPane.WARNING_MESSAGE JOptionPane.PLAIN_MESSAGEJOptionPane....
View Full Document

Page1 / 8

dialog boxes - CSc 2700: Lecture # 19 Dialog Boxes November...

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

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