Both the dialog class and the frame class are subclasses of window. A dialog box must depend on a window or component. When the window or component on which it depends disappears, the dialog box also disappears. When the window or component on it is visible, the dialog box is automatically restored.
I. Main Methods of the dialog class
1. Dialog (frame F, string S): constructs an initial invisible dialog box with the title S. F is the window on which the dialog box depends.
2. dialog (frame F, string S, Boolean B): constructs an initial invisible dialog box with the title S. F is the window on which the dialog box depends, B determines whether the dialog box is in mode or in mode.
3. gettitle (): gets the title of the dialog box.
4. settitle (): Set the title of the dialog box.
5. setmodal (Boolean B): Set the dialog box mode.
6. setsize (): Set the dialog box size.
7. setvisible (Boolean B): displays or hides the dialog box.
Ii. Dialog Box Mode
Mode dialog box: The activation status of the dialog box card allows the program to only respond to events in the dialog box. The program can no longer activate the window or component it depends on and block the execution of other threads.
The Mode-free dialog box is inactive. The program can still activate the window or component it depends on, and it does not block thread execution.
3. File Dialog Box filedialog
Filedialog is a subclass of dialog. The main methods include:
1. filedialog (frame F, string S, int mode): constructor. F is the dependent window object. S is the name of the dialog box. The mode value is filedialog. load or filedialog. save.
2. Public String getdirwctory (): gets the file directory displayed in the current dialog box.
3. Public String GetFile (): obtains the string representation of the file displayed in the dialog box. If the object does not exist, the value is null.
4. message dialog box
The message dialog box is a modal dialog box. You can call the static method of the joptionpane class in the javax. Swing package to create it:
Public static void showmessagedialog (Component parentcomponent,// Components on which the message dialog box depends
String message, // the message to be displayed
String title, // the title of the dialog box
Int messagetype); // the appearance of the dialog box. Optional values:
Joptionpane. information_message
Joptionpane. warning_message
Joptionpane. error_message
Joptionpane. question_message
Joptionpane. plain_message
5. confirmation dialog box
The confirmation dialog box is a modal dialog box. You can use the static method of the joptionpane class in the javax. Swing package to create it:
Public static int showconfirmdialog (Component parentcomponent,// Components on which the dialog box depends
Object mesage, // The message displayed in the dialog box
String title, // the title of the dialog box
Int optiontype); // the appearance of the dialog box. Optional values:
Joptionpane. yes_no_option
Joptionpane. yes_no_cancel_option
Joptionpane. OK _cancel_option
When the dialog box disappears, the showconfirmdialog method returns one of the following integers:
Joptionpane. yes_option
Joptionpane. no_option
Joptionpane. cancel_option
Joptionpane. OK _option
Joptionpane. closed_option
6. Color dialog box
Use the jcolorchooser class Table static method in the Java. Swing package to create a table:
Public static color showdialog (Component component, // component on which the dialog box depends
String title, // the title of the dialog box
Color initialcolor); // The default color returned when the dialog box disappears.