Magazine
 

Tips & Tricks

 

You can slide the knob at any desired position
as shown below:



4. Dialog Box In Swing Application

In non-swing application we were using System.in class for input or output some text or numeric values but now in the swing application we can use JOptionPane class to show the output or show the message. This way of inputting or outputting works very efficiently in the Swing Applications. The window for showing message for input or output makes your application very innovative.

JOptionPane class is available in the javax.swing package. This class provides various types of message dialog box as follows:

1. A simple message dialog box that has only one button i.e. “Ok”. This type of message dialog box is used only for showing the appropriate message and user can finish the message dialog box by clicking the “Ok” button.

2. A message dialog box that has two or three buttons. You can set several values for viewing several message dialog box as follows:

 

1.) “Yes” and “No”
2.) “Yes”, “No” and “Cancel”
3.) “Ok”, and “Cancel”
3. An input dialog box that contains two

buttons “Ok” and “Cancel”. The JOptionPane class has three methods as follows:

showMessageDialog(): First is the
showMessageDialog() method which is
used to display a simple message.

showInputDialog(): Second is the
showInputDialog() method which is used to display a prompt for inputting. This method returns a String value which is entered by you.

showConfirmDialog(): And the last or third method is the showConfirmDialog() which asks the user for confirmation (Yes/No) by displaying message. This method returns a numeric value either 0 or 1. If you click on the “Yes” button then the method returns 1 therwise 0.

I. Show dialog box.
Message dialog box is used to display informative messages to the user. In the example program, we will use JOptionPane class to display the message Dialog box. Our program display “Show Message” button on the window and when user clicks on it program displays Message box with “OK” button and message “JavaJazzUp”.

Description:

showMessageDialog():
This method is used to show a message dialog box which contains some text messages. This is being used with two arguments in the program
where the first argument is the parent object in which the dialog box opens and another is the message which has to be shown.


Jan 2007 | Java Jazz Up | 99
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 ,

83, 84 , 85 , 86, 87 , 88, 89 , 90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 , 100 , 101 , 102 , 103, 104 , 105 ,

106, 107,

Download PDF