安啾

啾咪~❤

JAVA JOptionPane APIs Note#1

Message Types

  1. ERROR_MESSAGE: Used for error messages. Display a red “X” icon on the dialog.

  2. QUESTION_MESSAGE: Used for question messages. Displays a question mark icon on the dialog.

  3. INFORMATION_MESSAGE: Used for information messages. Displays an information icon on the dialog.

  4. WARNING_MESSAGE: Used for warnings. Displays a yellow exclamation point icon on the dialog.

  5. PLAIN_MESSAGE: No icon is used.

Option Types

  1. DEFAULT_OPTION: Only displays one button: “OK”

  2. YES_NO_OPTION: Displays two buttons: “Yes”, “No”

  3. YES_NO_CANCEL_OPTION: Displays three buttons: “Yes”, “No”, “Cancel”

  4. OK_CANCEL_OPTION: Displays two buttons: “OK”, “Cancel”

[使用时用JOptionPane.ERROR_MESSAGE这样的格式作为变量。]


Message Dialog, showMessageDialog, method brings up a dialog that displays a message with an “OK” button and displays an icon determined by themessageType parameter.

public static void showMessageDialog(Component parentComponent, Object message, String title, int messageType);

Parameters:

  1. parentComponent: Should be set to null.

  2. message: The Object to display. Can be a String.

  3. title: The title string for the dialog

  4. messageType: The type of message to be displayed. Refer to the Message Types section above for a list of options.

Example:Create a dialog such that:  

The text of the dialog should be: "Sorry, that is incorrect. Please try again"  

The title of the dialog should be: "Invalid ID"  

The message type is ERROR  

Buttons: OK  

JOptionPane.showMessageDialog(null, "Sorry, that is incorrect. Please try again", "Invalid PUID",JOptionPane.ERROR_MESSAGE);

↑在其他方法里面 这么用

show several buttons, showOptionDialog, brings up a dialog with buttons. There can be either one, two or three buttons depending on the optionType parameter.

public static int showOptionDialog(Component parentComponent,                                    Object message,                                    String title,                                    int optionType,                                    int messageType,                                    Icon icon,                                    Object[] options,                                    Object initialValue)

Parameters:

  1. parentComponent: Determines the Frame in which the dialog is displayed; if null, or if the parentComponent has no Frame, a default Frame is used

  2. message: The Object to display. Can be a String.

  3. title: The title string for the dialog

  4. optionType: An integer designating the options available on the dialog. Refer to the Option Types section above for a list of options.

  5. messageType: An integer designating the kind of message this is, primarily used to determine the icon. Refer to the Message Types section above for a list of options.

  6. icon: A custom icon to display in the dialog. Can be null

  7. options: An array of objects indicating the possible choices the user can make. Can be a String array. The string objects in this array are used to override the default string on dialog buttons

  8. initialValue: the object that represents the default selection for the dialog; only meaningful if options is used; can be null

Return Valuean integer indicating the option chosen by the user, or CLOSED_OPTION if the user closed the dialog.







评论

© 安啾 | Powered by LOFTER