Java Reference
In-Depth Information
3.39
List the precedence order of the Boolean operators. Evaluate the following expressions:
Check
Point
true || true && false
true && true || false
3.40
True or false? All the binary operators except = are left associative.
3.41
Evaluate the following expressions:
2 * 2 - 3 > 2 && 4 - 2 > 5
2 * 2 - 3 > 2 || 4 - 2 > 5
3.42
Is (x > 0 && x < 10) the same as ((x > 0) && (x < 10)) ? Is (x > 0 || x <
10) the same as ((x > 0) || (x < 10)) ? Is (x > 0 || x < 10 && y < 0) the
same as (x > 0 || (x < 10 && y < 0)) ?
3.18 Confirmation Dialogs
You can use a confirmation dialog to obtain a confirmation from the user.
Key
Point
You have used showMessageDialog to display a message dialog box and
showInputDialog to display an input dialog box. Occasionally it is useful to answer a ques-
tion with a confirmation dialog box. A confirmation dialog can be created using the following
statement:
int option =
JOptionPane.showConfirmDialog
( null , "Continue" );
When a button is clicked, the method returns an option value. The value is
JOptionPane.YES_OPTION ( 0 ) for the Ye s button, JOptionPane.NO_OPTION ( 1 ) for the
No button, and JOptionPane.CANCEL_OPTION ( 2 ) for the Cancel button.
You may rewrite the guess-birthday program in Listing 3.3 using confirmation dialog
boxes, as shown in Listing 3.11. Figure 3.8 shows a sample run of the program for the day
19 .
L ISTING 3.11 GuessBirthdayUsingConfirmationDialog.java
1 import javax.swing.JOptionPane;
2
3 public class GuessBirthdayUsingConfirmationDialog {
4
import class
public static void main(String[] args) {
5
6
String set1 =
set1
" 1 3 5 7\n" +
7
" 9 11 13 15\n" +
8
"17 19 21 23\n" +
9
"25 27 29 31" ;
10
11
12
String set2 =
set2
" 2 3 6 7\n" +
13
"10 11 14 15\n" +
14
"18 19 22 23\n" +
15
"26 27 30 31" ;
16
 
 
Search WWH ::




Custom Search