- Page 2:
ONLINE ACCESS Thank you for purchas
- Page 6:
This page intentionally left blank
- Page 10:
Editorial Director: Marcia Horton E
- Page 14:
This page intentionally left blank
- Page 18:
viii Preface complete revision new
- Page 22:
x Preface Organization of the Book
- Page 26:
xii Preface ■ ■ Instructors can
- Page 30:
xiv Preface Tront (Simon Fraser Uni
- Page 34:
CONTENTS Chapter 1 Introduction to
- Page 38:
xviii Contents 5.6 Modularizing Cod
- Page 42:
xx Contents 11.11 The ArrayList Cla
- Page 46:
xxii Contents 17.7 Sliders 657 17.8
- Page 50:
VideoNote VideoNotes Locations of V
- Page 54:
xxvi VideoNotes Chapter 19 Chapter
- Page 58:
2 Chapter 1 Introduction to Compute
- Page 62:
4 Chapter 1 Introduction to Compute
- Page 66:
6 Chapter 1 Introduction to Compute
- Page 70:
8 Chapter 1 Introduction to Compute
- Page 74:
10 Chapter 1 Introduction to Comput
- Page 78:
12 Chapter 1 Introduction to Comput
- Page 82:
14 Chapter 1 Introduction to Comput
- Page 86:
16 Chapter 1 Introduction to Comput
- Page 90:
18 Chapter 1 Introduction to Comput
- Page 94:
20 Chapter 1 Introduction to Comput
- Page 98:
22 Chapter 1 Introduction to Comput
- Page 102:
24 Chapter 1 Introduction to Comput
- Page 106:
26 Chapter 1 Introduction to Comput
- Page 110:
28 Chapter 1 Introduction to Comput
- Page 114:
30 Chapter 1 Introduction to Comput
- Page 118:
32 Chapter 1 Introduction to Comput
- Page 122:
34 Chapter 2 Elementary Programming
- Page 126:
36 Chapter 2 Elementary Programming
- Page 130:
38 Chapter 2 Elementary Programming
- Page 134:
40 Chapter 2 Elementary Programming
- Page 138:
42 Chapter 2 Elementary Programming
- Page 142:
44 Chapter 2 Elementary Programming
- Page 146:
46 Chapter 2 Elementary Programming
- Page 150:
48 Chapter 2 Elementary Programming
- Page 154:
50 Chapter 2 Elementary Programming
- Page 158:
52 Chapter 2 Elementary Programming
- Page 162:
54 Chapter 2 Elementary Programming
- Page 166:
56 Chapter 2 Elementary Programming
- Page 170:
58 Chapter 2 Elementary Programming
- Page 174:
60 Chapter 2 Elementary Programming
- Page 178:
62 Chapter 2 Elementary Programming
- Page 182:
64 Chapter 2 Elementary Programming
- Page 186:
66 Chapter 2 Elementary Programming
- Page 190:
68 Chapter 2 Elementary Programming
- Page 194:
70 Chapter 2 Elementary Programming
- Page 198:
72 Chapter 2 Elementary Programming
- Page 202:
74 Chapter 2 Elementary Programming
- Page 206:
76 Chapter 2 Elementary Programming
- Page 210:
78 Chapter 2 Elementary Programming
- Page 214:
80 Chapter 2 Elementary Programming
- Page 218:
82 Chapter 3 Selections problem sel
- Page 222:
84 Chapter 3 Selections ✓Point✓
- Page 226:
86 Chapter 3 Selections Enter an in
- Page 230:
88 Chapter 3 Selections in Set4? in
- Page 234:
90 Chapter 3 Selections Here is the
- Page 238:
92 Chapter 3 Selections score >= 90
- Page 242:
94 Chapter 3 Selections Common Erro
- Page 246:
96 Chapter 3 Selections VideoNote P
- Page 250:
98 Chapter 3 Selections LISTING 3.5
- Page 254:
100 Chapter 3 Selections input stat
- Page 258:
102 Chapter 3 Selections to create
- Page 262:
104 Chapter 3 Selections incompatib
- Page 266:
106 Chapter 3 Selections input leap
- Page 270:
108 Chapter 3 Selections Key Point
- Page 274:
110 Chapter 3 Selections Now let us
- Page 278:
112 Chapter 3 Selections The result
- Page 282:
114 Chapter 3 Selections Here is an
- Page 286:
116 Chapter 3 Selections operator p
- Page 290:
118 Chapter 3 Selections set3 set4
- Page 294:
120 Chapter 3 Selections ■ Settin
- Page 298:
122 Chapter 3 Selections Note that
- Page 302:
124 Chapter 3 Selections example, i
- Page 306:
126 Chapter 3 Selections y-axis (9,
- Page 310:
128 Chapter 3 Selections Enter a po
- Page 314:
130 Chapter 3 Selections Enter the
- Page 318:
This page intentionally left blank
- Page 322:
134 Chapter 4 Loops problem Key Poi
- Page 326:
136 Chapter 4 Loops This loop is in
- Page 330:
138 Chapter 4 Loops too low? 20 Sys
- Page 334:
140 Chapter 4 Loops get start time
- Page 338:
142 Chapter 4 Loops loop end of loo
- Page 342:
144 Chapter 4 Loops 4.4 Suppose the
- Page 346:
146 Chapter 4 Loops ✓Point✓ Che
- Page 350:
148 Chapter 4 Loops initial-action
- Page 354:
150 Chapter 4 Loops pretest loop po
- Page 358:
152 Chapter 4 Loops nested loop tab
- Page 362:
154 Chapter 4 Loops VideoNote Minim
- Page 366:
156 Chapter 4 Loops input input gcd
- Page 370:
158 Chapter 4 Loops 4.8.3 Case Stud
- Page 374:
160 Chapter 4 Loops continue LISTIN
- Page 378:
162 Chapter 4 Loops 4.24 Rewrite th
- Page 382:
164 Chapter 4 Loops The first 50 pr
- Page 386:
166 Chapter 4 Loops CHAPTER SUMMARY
- Page 390:
168 Chapter 4 Loops 4.6 (Conversion
- Page 394:
170 Chapter 4 Loops VideoNote Displ
- Page 398:
172 Chapter 4 Loops *4.30 (Financia
- Page 402:
174 Chapter 4 Loops *4.42 (Financia
- Page 406:
This page intentionally left blank
- Page 410:
178 Chapter 5 Methods problem why m
- Page 414:
180 Chapter 5 Methods define vs. de
- Page 418:
182 Chapter 5 Methods public static
- Page 422:
184 Chapter 5 Methods getGrade meth
- Page 426:
186 Chapter 5 Methods Key Point par
- Page 430:
188 Chapter 5 Methods The values of
- Page 434:
190 Chapter 5 Methods invoke gcd co
- Page 438:
192 Chapter 5 Methods For example,
- Page 442:
194 Chapter 5 Methods method overlo
- Page 446:
196 Chapter 5 Methods } public stat
- Page 450:
198 Chapter 5 Methods /** Convert t
- Page 454:
200 Chapter 5 Methods Math.abs(-2)
- Page 458:
202 Chapter 5 Methods Hence, a rand
- Page 462:
204 Chapter 5 Methods Enter full ye
- Page 466:
206 Chapter 5 Methods printCalendar
- Page 470:
208 Chapter 5 Methods printMonth pr
- Page 474:
210 Chapter 5 Methods isLeapYear 11
- Page 478:
212 Chapter 5 Methods PROGRAMMING E
- Page 482:
214 Chapter 5 Methods /** Convert f
- Page 486:
216 Chapter 5 Methods 5.18 (Use the
- Page 490:
218 Chapter 5 Methods Comprehensive
- Page 494:
220 Chapter 5 Methods 5. If the res
- Page 498:
222 Chapter 5 Methods Write a test
- Page 502:
224 Chapter 6 Single-Dimensional Ar
- Page 506:
226 Chapter 6 Single-Dimensional Ar
- Page 510:
228 Chapter 6 Single-Dimensional Ar
- Page 514:
230 Chapter 6 Single-Dimensional Ar
- Page 518:
232 Chapter 6 Single-Dimensional Ar
- Page 522:
234 Chapter 6 Single-Dimensional Ar
- Page 526:
236 Chapter 6 Single-Dimensional Ar
- Page 530:
238 Chapter 6 Single-Dimensional Ar
- Page 534:
240 Chapter 6 Single-Dimensional Ar
- Page 538:
242 Chapter 6 Single-Dimensional Ar
- Page 542:
244 Chapter 6 Single-Dimensional Ar
- Page 546:
246 Chapter 6 Single-Dimensional Ar
- Page 550:
248 Chapter 6 Single-Dimensional Ar
- Page 554:
250 Chapter 6 Single-Dimensional Ar
- Page 558:
252 Chapter 6 Single-Dimensional Ar
- Page 562:
254 Chapter 6 Single-Dimensional Ar
- Page 566:
256 Chapter 6 Single-Dimensional Ar
- Page 570:
258 Chapter 6 Single-Dimensional Ar
- Page 574:
260 Chapter 6 Single-Dimensional Ar
- Page 578:
262 Chapter 6 Single-Dimensional Ar
- Page 582:
264 Chapter 7 Multidimensional Arra
- Page 586:
266 Chapter 7 Multidimensional Arra
- Page 590:
268 Chapter 7 Multidimensional Arra
- Page 594:
270 Chapter 7 Multidimensional Arra
- Page 598:
272 Chapter 7 Multidimensional Arra
- Page 602:
274 Chapter 7 Multidimensional Arra
- Page 606:
276 Chapter 7 Multidimensional Arra
- Page 610:
278 Chapter 7 Multidimensional Arra
- Page 614:
280 Chapter 7 Multidimensional Arra
- Page 618:
282 Chapter 7 Multidimensional Arra
- Page 622:
284 Chapter 7 Multidimensional Arra
- Page 626:
286 Chapter 7 Multidimensional Arra
- Page 630:
288 Chapter 7 Multidimensional Arra
- Page 634:
290 Chapter 7 Multidimensional Arra
- Page 638:
292 Chapter 7 Multidimensional Arra
- Page 642:
294 Chapter 7 Multidimensional Arra
- Page 646:
296 Chapter 8 Objects and Classes w
- Page 650:
298 Chapter 8 Objects and Classes U
- Page 654:
300 Chapter 8 Objects and Classes T
- Page 658:
302 Chapter 8 Objects and Classes s
- Page 662:
304 Chapter 8 Objects and Classes K
- Page 666:
306 Chapter 8 Objects and Classes }
- Page 670:
308 Chapter 8 Objects and Classes 1
- Page 674:
310 Chapter 8 Objects and Classes W
- Page 678:
312 Chapter 8 Objects and Classes c
- Page 682:
314 Chapter 8 Objects and Classes 2
- Page 686:
316 Chapter 8 Objects and Classes N
- Page 690:
318 Chapter 8 Objects and Classes u
- Page 694:
320 Chapter 8 Objects and Classes A
- Page 698:
322 Chapter 8 Objects and Classes S
- Page 702:
324 Chapter 8 Objects and Classes S
- Page 706:
326 Chapter 8 Objects and Classes 8
- Page 710:
328 Chapter 8 Objects and Classes 8
- Page 714:
330 Chapter 8 Objects and Classes T
- Page 718:
332 Chapter 8 Objects and Classes
- Page 722:
334 Chapter 8 Objects and Classes T
- Page 726:
336 Chapter 9 Strings Key Point Key
- Page 730:
338 Chapter 9 Strings java.lang.Str
- Page 734:
340 Chapter 9 Strings string index
- Page 738:
342 Chapter 9 Strings why regular e
- Page 742:
344 Chapter 9 Strings To convert an
- Page 746:
346 Chapter 9 Strings 9.5 Let s1 be
- Page 750:
348 Chapter 9 Strings low index hig
- Page 754:
350 Chapter 9 Strings hex char to d
- Page 758:
352 Chapter 9 Strings input string
- Page 762:
354 Chapter 9 Strings java.lang.Str
- Page 766:
356 Chapter 9 Strings the builder
- Page 770:
358 Chapter 9 Strings 9.20 Suppose
- Page 774:
360 Chapter 9 Strings Add Subtract
- Page 778:
362 Chapter 9 Strings 4. You can us
- Page 782:
364 Chapter 9 Strings Enter a strin
- Page 786:
366 Chapter 9 Strings **9.18 (Imple
- Page 790:
368 Chapter 9 Strings Enter a genom
- Page 794:
370 Chapter 10 Thinking in Objects
- Page 798:
372 Chapter 10 Thinking in Objects
- Page 802:
374 Chapter 10 Thinking in Objects
- Page 806:
376 Chapter 10 Thinking in Objects
- Page 810:
378 Chapter 10 Thinking in Objects
- Page 814:
380 Chapter 10 Thinking in Objects
- Page 818:
382 Chapter 10 Thinking in Objects
- Page 822:
384 Chapter 10 Thinking in Objects
- Page 826:
386 Chapter 10 Thinking in Objects
- Page 830:
388 Chapter 10 Thinking in Objects
- Page 834:
390 Chapter 10 Thinking in Objects
- Page 838:
392 Chapter 10 Thinking in Objects
- Page 842: 394 Chapter 10 Thinking in Objects
- Page 846: 396 Chapter 10 Thinking in Objects
- Page 850: 398 Chapter 10 Thinking in Objects
- Page 854: 400 Chapter 10 Thinking in Objects
- Page 858: 402 Chapter 10 Thinking in Objects
- Page 862: 404 Chapter 10 Thinking in Objects
- Page 866: 406 Chapter 10 Thinking in Objects
- Page 870: 408 Chapter 11 Inheritance and Poly
- Page 874: 410 Chapter 11 Inheritance and Poly
- Page 878: 412 Chapter 11 Inheritance and Poly
- Page 882: 414 Chapter 11 Inheritance and Poly
- Page 886: 416 Chapter 11 Inheritance and Poly
- Page 890: 418 Chapter 11 Inheritance and Poly
- Page 896: 11.7 Polymorphism 421 important to
- Page 900: 11.8 Dynamic Binding 423 C n C n-1
- Page 904: 11.9 Casting Objects and the instan
- Page 908: 11.9 Casting Objects and the instan
- Page 912: 11.10 The Object’s equals Method
- Page 916: class, which can be used to store a
- Page 920: 11.11 The ArrayList Class 433 List
- Page 924: 11.11 The ArrayList Class 435 18 19
- Page 928: 11.13 The protected Data and Method
- Page 932: 11.14 Preventing Extending and Over
- Page 936: 2. A constructor is used to constru
- Page 940: Draw the UML diagram for the classe
- Page 944:
CHAPTER 12 GUI BASICS Objectives
- Page 948:
12.3 The Java GUI API 447 Dimension
- Page 952:
12.4 Frames 449 12.4 Frames A frame
- Page 956:
This was cumbersome. Versions of Ja
- Page 960:
12.5 Layout Managers 453 26 frame.s
- Page 964:
■ If both the number of rows and
- Page 968:
12.5 Layout Managers 457 4 5 public
- Page 972:
The Swing version of panel is JPane
- Page 976:
You can use the setBackground(Color
- Page 980:
12.9 Common Features of Swing GUI C
- Page 984:
12.10 Image Icons 465 12 frame.setV
- Page 988:
12.11 JButton 467 Tip A splash scre
- Page 992:
12.11 JButton 469 JButton inherits
- Page 996:
constants TOP, CENTER, or BOTTOM, a
- Page 1000:
12.14 Labels 473 To group radio but
- Page 1004:
Chapter Summary 475 Note If a text
- Page 1008:
Sections 12.7-12.15 12.6 (Display i
- Page 1012:
CHAPTER 13 GRAPHICS Objectives ■
- Page 1016:
13.2 The Graphics Class 481 java.aw
- Page 1020:
13.3 Drawing Strings, Lines, Rectan
- Page 1024:
13.4 Case Study: The FigurePanel Cl
- Page 1028:
13.4 Case Study: The FigurePanel Cl
- Page 1032:
13.5 Drawing Arcs 489 Listing 13.4
- Page 1036:
Here is an example of creating a po
- Page 1040:
13.7 Centering a String Using the F
- Page 1044:
13.8 Case Study: The MessagePanel C
- Page 1048:
13.8 Case Study: The MessagePanel C
- Page 1052:
13.8 Case Study: The MessagePanel C
- Page 1056:
13.9 Case Study: The StillClock Cla
- Page 1060:
13.9 Case Study: The StillClock Cla
- Page 1064:
13.10 Displaying Images 505 java.aw
- Page 1068:
27 frame.setDefaultCloseOperation(J
- Page 1072:
2. Whenever a component (e.g., a bu
- Page 1076:
Programming Exercises 511 FIGURE 13
- Page 1080:
Programming Exercises 513 (a) (b) (
- Page 1084:
Programming Exercises 515 (a) (b) (
- Page 1088:
CHAPTER 14 EXCEPTION HANDLING AND T
- Page 1092:
14.2 Exception-Handling Overview 51
- Page 1096:
14.2 Exception-Handling Overview 52
- Page 1100:
14.3 Point out the problem in the f
- Page 1104:
14.3 Exception Types 525 ■ Runtim
- Page 1108:
must be nonnegative, but a negative
- Page 1112:
14.4 More on Exception Handling 529
- Page 1116:
14.4 More on Exception Handling 531
- Page 1120:
14.13 Suppose that statement2 cause
- Page 1124:
14.6 When to Use Exceptions 535 fin
- Page 1128:
14.8 Chained Exceptions 537 } perfo
- Page 1132:
14.9 Defining Custom Exception Clas
- Page 1136:
14.10 The File Class 541 } } } catc
- Page 1140:
separator, which is the same as on
- Page 1144:
14.11 File Input and Output 545 5 S
- Page 1148:
14.11 File Input and Output 547 How
- Page 1152:
14.12 File Dialogs 549 37 input.clo
- Page 1156:
14.13 Reading Data from the Web 551
- Page 1160:
Chapter Summary 553 CHAPTER SUMMARY
- Page 1164:
Triangle class to throw an IllegalT
- Page 1168:
**14.20 (Remove package statement)
- Page 1172:
CHAPTER 15 ABSTRACT CLASSES AND INT
- Page 1176:
15.2 Abstract Classes 561 The # sig
- Page 1180:
15.2 Abstract Classes 563 7 8 Syste
- Page 1184:
15.3 Case Study: the Abstract Numbe
- Page 1188:
15.4 Case Study: Calendar and Grego
- Page 1192:
15.4 Case Study: Calendar and Grego
- Page 1196:
15.5 Interfaces 571 11 } 12 } 13 }
- Page 1200:
15.14 Suppose A is an interface. Ca
- Page 1204:
15.6 The Comparable Interface 575 1
- Page 1208:
15.18 Which of the following is the
- Page 1212:
15.7 The Cloneable Interface 579 13
- Page 1216:
15.8 Interfaces vs. Abstract Classe
- Page 1220:
classes. Consider the Animal class.
- Page 1224:
Java provides data types for intege
- Page 1228:
15.9 Case Study: The Rational Class
- Page 1232:
15.9 Case Study: The Rational Class
- Page 1236:
Programming Exercises 591 } protect
- Page 1240:
Programming Exercises 593 Sections
- Page 1244:
You can also obtain the absolute va
- Page 1248:
iteration count (line 28). The meth
- Page 1252:
CHAPTER 16 EVENT-DRIVEN PROGRAMMING
- Page 1256:
The ActionListener interface contai
- Page 1260:
TABLE 16.1 User Action, Source Obje
- Page 1264:
16.3 Listeners, Registrations, and
- Page 1268:
16.3 Listeners, Registrations, and
- Page 1272:
For example, canvas is defined in C
- Page 1276:
16.5 Anonymous Class Listeners 611
- Page 1280:
16.6 Alternative Ways of Defining L
- Page 1284:
16.7 Case Study: Loan Calculator 61
- Page 1288:
The user interface is created in th
- Page 1292:
16.8 Mouse Events 619 7 // Create a
- Page 1296:
16.10 Key Events 621 16.16 Why does
- Page 1300:
16.10 Key Events 623 29 private int
- Page 1304:
16.11 Animation Using the Timer Cla
- Page 1308:
16.11 Animation Using the Timer Cla
- Page 1312:
Chapter Summary 629 16.23 How do yo
- Page 1316:
*16.5 (Create an investment-value c
- Page 1320:
**16.20 (Geometry: inside a rectang
- Page 1324:
***16.28 (Simulation: self-avoiding
- Page 1328:
Programming Exercises 637 FIGURE 16
- Page 1332:
CHAPTER 17 GUI COMPONENTS Objective
- Page 1336:
17.2 Events for JCheckBox, JRadioBu
- Page 1340:
17.2 Events for JCheckBox, JRadioBu
- Page 1344:
17.3 Text Areas 645 DescriptionPane
- Page 1348:
17.4 Combo Boxes 647 12 frame.setDe
- Page 1352:
17.4 Combo Boxes 649 LISTING 17.4 C
- Page 1356:
17.5 Lists 651 javax.swing.JCompone
- Page 1360:
17.5 Lists 653 29 // Arrays of labe
- Page 1364:
17.6 Scroll Bars 655 javax.swing.JC
- Page 1368:
17.7 Sliders 657 When the user drag
- Page 1372:
17.7 Sliders 659 4 5 public class S
- Page 1376:
3. Implement the actionPerformed ha
- Page 1380:
17.8 Creating Multiple Windows 663
- Page 1384:
Programming Exercises 665 FigurePan
- Page 1388:
**17.9 (Demonstrate JLabel properti
- Page 1392:
Sections 17.6-17.8 **17.15 (Use JSc
- Page 1396:
CHAPTER 18 APPLETS AND MULTIMEDIA O
- Page 1400:
4 public DisplayLabel() { 5 add(new
- Page 1404:
18.4 Applet Security Restrictions 6
- Page 1408:
18.6 Applet Life-Cycle Methods 677
- Page 1412:
18.7 Passing Strings to Applets 679
- Page 1416:
18.7 Passing Strings to Applets 681
- Page 1420:
18.14 What is wrong if the DisplayM
- Page 1424:
37 if (y < 0 || y > getHeight()) 38
- Page 1428:
18.9 Case Study: Developing a Tic-T
- Page 1432:
18.9 Case Study: Developing a Tic-T
- Page 1436:
18.10 Locating Resources Using the
- Page 1440:
18.11 Playing Audio in Any Java Pro
- Page 1444:
18.12 Case Study: National Flags an
- Page 1448:
The presentNation(index) method (li
- Page 1452:
Programming Exercises 699 **18.5
- Page 1456:
equest that the elevator come to hi
- Page 1460:
Programming Exercises 703 (a) FIGUR
- Page 1464:
Programming Exercises 705 FIGURE 18
- Page 1468:
is changed to Pause, as shown in Fi
- Page 1472:
CHAPTER 19 BINARY I/O Objectives
- Page 1476:
19.3 Text I/O vs. Binary I/O 711 Pr
- Page 1480:
19.4 Binary I/O Classes 713 java.io
- Page 1484:
19.4 Binary I/O Classes 715 15 // C
- Page 1488:
19.4 Binary I/O Classes 717 OutputS
- Page 1492:
Caution You have to read data in th
- Page 1496:
If no buffer size is specified, the
- Page 1500:
19.5 Case Study: Copying Files 723
- Page 1504:
19.6 Object I/O 725 java.io.InputSt
- Page 1508:
19.6 Object I/O 727 19.6.1 The Seri
- Page 1512:
19.7 Random-Access Files 729 19.25
- Page 1516:
RandomAccessFile. A large case stud
- Page 1520:
Programming Exercises 733 CHAPTER S
- Page 1524:
Programming Exercises 735 (a) (b) F
- Page 1528:
CHAPTER 20 RECURSION Objectives ■
- Page 1532:
20.2 Case Study: Computing Factoria
- Page 1536:
Pedagogical Note It is simpler and
- Page 1540:
20.3 Case Study: Computing Fibonacc
- Page 1544:
20.4 Problem Solving Using Recursio
- Page 1548:
15 public static void main(String[]
- Page 1552:
20.6 Case Study: Finding the Direct
- Page 1556:
20.7 Case Study: Towers of Hanoi 75
- Page 1560:
20.7 Case Study: Towers of Hanoi 75
- Page 1564:
How do you draw a Sierpinski triang
- Page 1568:
20.9 Recursion vs. Iteration 757 p1
- Page 1572:
Chapter Summary 759 LISTING 20.10 C
- Page 1576:
*20.7 (Fibonacci series) Modify Lis
- Page 1580:
Write a test program that prompts t
- Page 1584:
***20.32 (Game: Knight’s Tour) Th
- Page 1588:
Programming Exercises 767 FIGURE 20
- Page 1592:
APPENDIXES Appendix A Java Keywords
- Page 1596:
APPENDIX A Java Keywords The follow
- Page 1600:
TABLE B.1 ASCII Character Set in th
- Page 1604:
Appendix C 775 Operator Name Associ
- Page 1608:
Appendix D 777 Modifier Class Const
- Page 1612:
Number Systems APPENDIX F F.1 Intro
- Page 1616:
Appendix F 781 F.3 Conversions Betw
- Page 1620:
Bitwise Operations APPENDIX G To wr
- Page 1624:
INDEX Symbols -- (decrement operato
- Page 1628:
Index 787 passing to methods, 237-2
- Page 1632:
Index 789 Celsius, converting to/fr
- Page 1636:
Index 791 Constructor chaining, 415
- Page 1640:
Index 793 Event delegation, 603 Eve
- Page 1644:
Index 795 Gene sequences, 367 Genom
- Page 1648:
Index 797 casting objects and, 425-
- Page 1652:
Index 799 javax.swing. see Swing JB
- Page 1656:
Index 801 do-while loop, 144-146 in
- Page 1660:
Index 803 O Object class, 420-421,
- Page 1664:
Index 805 writing data to file usin
- Page 1668:
Index 807 Scroll panes DescriptionP
- Page 1672:
Index 809 combo boxes. see JComboBo
- Page 1676:
Index 811 Vertical scroll bars, 656
- Page 1680:
Java Quick Reference Frequently Use
- Page 1684:
***This is a bonus Web chapter CHAP
- Page 1688:
java.util.Locale +Locale(language:
- Page 1692:
35.3.1 The TimeZone Class TimeZone
- Page 1696:
DateFormatSymbols symbols = new Dat
- Page 1700:
37 (DateFormat.MEDIUM, DateFormat.L
- Page 1704:
An instance of StillClock is create
- Page 1708:
13 14 private java.util.Calendar ca
- Page 1712:
129 showDays(); 130 } 131 132 /** R
- Page 1716:
50 if (e.getSource() == jcboLocale)
- Page 1720:
You can control the display of numb
- Page 1724:
1 import java.awt.*; 2 import
- Page 1728:
109 public void actionPerformed(Act
- Page 1732:
The first method returns a Resource
- Page 1736:
Number_Formatting=demonstration du
- Page 1740:
99 jtfFormattedLoanAmount.setHorizo
- Page 1744:
Property resource bundles are imple
- Page 1748:
Chapter Summary 1. Java is the firs
- Page 1752:
(Display date and time) Write a pro
- Page 1756:
(Specify file encodings) Write a pr
- Page 1760:
36.1 Introduction Every Java user i
- Page 1764:
public void setMessage(String s) pu
- Page 1768:
Source Component Register listener
- Page 1772:
public void removeListener(Listener
- Page 1776:
63 } 64 } 65 66 /** Fire ActionEven
- Page 1780:
22 public void actionPerformed(Acti
- Page 1784:
4 } An event class is an extension
- Page 1788:
egistration and deregistration meth
- Page 1792:
Key Terms write the code to generat
- Page 1796:
Whenever the hurricane category is
- Page 1800:
java.util.EventObject java.util.Eve
- Page 1804:
37.1 Introduction Chapter 12, “
- Page 1808:
esizable is a boolean value indicat
- Page 1812:
from the origin, 0.5 is centered, a
- Page 1816:
1 import java.awt.*; 2 impor
- Page 1820:
BoxLayout boxLayout = new BoxLayout
- Page 1824:
20 private ImageIcon imageIconGerma
- Page 1828:
1. Use this statement to specify a
- Page 1832:
public void removeLayoutComponent(C
- Page 1836:
25 26 public Dimension preferredLay
- Page 1840:
17 new JRadioButton("FlowLayout");
- Page 1844:
javax.swing.JComponent javax.swing.
- Page 1848:
18 JComboBox jcboMap = new JComboBo
- Page 1852:
given title and/or icon. Figure 37.
- Page 1856:
javax.swing.JComponent javax.swing.
- Page 1860:
50 jpComponents.add(new JButton("Bu
- Page 1864:
[BL]EtchedBorder is an etched borde
- Page 1868:
Listing 37.9 gives an example that
- Page 1872:
43 jpPosition.add(jrbBelowTop = new
- Page 1876:
161 border = new MatteBorder(15, 15
- Page 1880:
Do the test questions for this chap
- Page 1884:
37.4* (Use CardLayout) Write an app
- Page 1888:
***This is a bonus Web chapter CHAP
- Page 1892:
(a) (b) (c) Figure 38.1 (a) The men
- Page 1896:
The new icons and mnemonics are sho
- Page 1900:
32 // Add menu items with mnemonics
- Page 1904:
The private method calculate(char o
- Page 1908:
25 add(new JScrollPane(jTextArea1),
- Page 1912:
Figure 38.5 The toolbar contains th
- Page 1916:
«interface» java.awt.event.Action
- Page 1920:
12 "/image/leftAlignment.png")); 13
- Page 1924:
(a) (b) Figure 38.10 (a) A JOptionP
- Page 1928:
The parameters parentComponent, mes
- Page 1932:
38.6.5 Example: Creating JOptionPan
- Page 1936:
70 JOptionPane.showMessageDialog(nu
- Page 1940:
47 jpSliders.add(jslGreen); 48 jpSl
- Page 1944:
dialog is set modal in line 24 in C
- Page 1948:
desired, but often you create an in
- Page 1952:
42 // Add menu items to the menu 43
- Page 1956:
174 175 // Display the status of th
- Page 1960:
38.4 How do you set an icon and a t
- Page 1964:
38.4* (Use actions) Write a program
- Page 1968:
Figure 38.29 The new TicTacToe game
- Page 1972:
39.1 Introduction The Swing user in
- Page 1976:
1 import java.awt.event.*; 2 im
- Page 1980:
6 7 /** Set a model */ 8 public voi
- Page 1984:
2 import java.awt.event.*; 3 import
- Page 1988:
Another variation of the model-view
- Page 1992:
JSpinner, JList, JComboBox, JTable,
- Page 1996:
18 spinner.addChangeListener(new Ch
- Page 2000:
maximum properties can be null to i
- Page 2004:
The JSpinner's constructor creates
- Page 2008:
88 numberModel.setMaximum(new Integ
- Page 2012:
39.7.1 JList Constructors, Properti
- Page 2016:
model, because the DefaultListSelec
- Page 2020:
80 Object[] values = jlst.getSelect
- Page 2024:
AbstractListModel implements the Li
- Page 2028:
The new item is inserted before the
- Page 2032:
15 boolean cellHasFocus) { 16 Objec
- Page 2036:
35 bigIcons[i] = new ImageIcon(getC
- Page 2040:
ListModel ComboBoxModel AbstractLis
- Page 2044:
34 } 35 36 // Set list cell rendere
- Page 2048:
39.2 How do you do implement models
- Page 2052:
SpinnerModelEditorDemo.java. Improv
- Page 2056:
(a) The list displays geometrical s
- Page 2060:
40.1 Introduction The preceding cha
- Page 2064:
an array, or row data and column he
- Page 2068:
20 }; 21 22 // Create a table 23 pr
- Page 2072:
AbstractTableModel and implement at
- Page 2076:
TableModel and DefaultTableModel co
- Page 2080:
14 15 // Create a table 16 private
- Page 2084:
1 import javax.swing.*; 2 import
- Page 2088:
(a) (b) Figure 40.14 You can add a
- Page 2092:
75 JPanel panel5 = new JPanel(); 76
- Page 2096:
207 } 208 209 private Vector getCol
- Page 2100:
Listing 40.7 gives a custom table m
- Page 2104:
This method signature is very simil
- Page 2108:
} } This example uses the same tabl
- Page 2112:
54 private JTextArea jtaMessage = n
- Page 2116:
Figure 40.18 JTree displays data in
- Page 2120:
javax.swing.JTree #cellEditor: Tree
- Page 2124:
29 private JComboBox jcboShowsRootH
- Page 2128:
«interface» javax.swing.tree.Tree
- Page 2132:
«interface» javax.swing.tree.Tree
- Page 2136:
14 europe.add(new DefaultMutableTre
- Page 2140:
«interface» javax.swing.tree.Tree
- Page 2144:
27 jtaOutput.append("\nProcessing a
- Page 2148:
13 private JCheckBox jchkEditable =
- Page 2152:
145 ((DefaultTreeModel)(jTree2.getM
- Page 2156:
40.15 Tree Events JTree can fire Tr
- Page 2160:
enables the user to enter or choose
- Page 2164:
Sections 40.8-40.14 40.6* (Create a
- Page 2168:
***This is a bonus Web chapter CHAP
- Page 2172:
import java.awt.*; import java.awt
- Page 2176:
} jbtClearSQLCommand.addActionListe
- Page 2180:
method is invoked (lines 208-221).
- Page 2184:
"jdbc:oracle:thin:@liang.armstrong.
- Page 2188:
input = new Scanner(new File(filena
- Page 2192:
CONCUR_UPDATABLE: The result set ca
- Page 2196:
} } } Driver loaded Database conne
- Page 2200:
«interface» java.sql.ResultSet «
- Page 2204:
import java.sql.*; import javax.sql
- Page 2208:
} } System.out.println("After updat
- Page 2212:
int column). The AbstractTableModel
- Page 2216:
} } System.out.println("Cursor move
- Page 2220:
jPanel1.add(jcboURL); jPanel1.add(j
- Page 2224:
} /** Create a TableEditor */ publi
- Page 2228:
int selectedRow = jTable1.getSelect
- Page 2232:
import java.sql.*; impo
- Page 2236:
} } private void retrieveFlagInfo(S
- Page 2240:
Use the Math.random() method to gen
- Page 2244:
The Country table is displayed in a
- Page 2248:
42.1 Introduction Servlets are Jav
- Page 2252:
The two most common HTTP requests,
- Page 2256:
} } HttpServletResponse response) t
- Page 2260:
3. Select the checkbox to add the s
- Page 2264:
You can deploy a Web application us
- Page 2268:
doPut is invoked to respond to a PU
- Page 2272:
«interface» javax.servlet.Servlet
- Page 2276:
NOTE: The URL query string uses the
- Page 2280:
The following HTML tags are used
- Page 2284:
String remarks = request.getParamet
- Page 2288:
} } allLocale[i].getDisplayName() +
- Page 2292:
The servlet processes the form and
- Page 2296:
} String phone = request.getParamet
- Page 2300:
The next request will submit the da
- Page 2304:
import javax.servlet.*; import java
- Page 2308:
} } catch (Exception ex) { System.o
- Page 2312:
public class RegistrationWithCookie
- Page 2316:
} " is now registered in the databa
- Page 2320:
«interface» javax.servlet.http.Ht
- Page 2324:
} // Set the action for processing
- Page 2328:
private String street; private Stri
- Page 2332:
Figure 42.25 The servlet returns an
- Page 2336:
package chapter42; import javax.ser
- Page 2340:
The servlet in the preceding exampl
- Page 2344:
through an I/O stream on the HttpSe
- Page 2348:
42.15 The statement out.close() is
- Page 2352:
Section 42.6 42.4* 2. Store the cou
- Page 2356:
(a) (b) Figure 42.33 The user enter
- Page 2360:
Figure 42.37 The web page lets you
- Page 2364:
43.1 Introduction Servlets can be u
- Page 2368:
Figure 43.4 A JSP page is translate
- Page 2372:
%> } if (n == 0) return 1; else ret
- Page 2376:
Compute Loan Payment Loan Amount
- Page 2380:
errorPage="HandleError.jsp" %> spec
- Page 2384:
Figure 43.7 The number of visits to
- Page 2388:
public void increaseCount() { count
- Page 2392:
creates a bean named loan for the L
- Page 2396:
method factorialBeanId.getFactorial
- Page 2400:
package chapter43; import j
- Page 2404:
Create DisplayTime.jsp (Listing 43.
- Page 2408:
The HTML file that displays the for
- Page 2412:
Web applications developed using JS
- Page 2416:
} ex.printStackTrace(); } return ta
- Page 2420:
Table No tables Select a
- Page 2424:
Java statements inserted in the jsp
- Page 2428:
43.8 What is wrong if the JSP scrip
- Page 2432:
(a) (b) Figure 43.13 The program di
- Page 2436:
***This is a bonus Web chapter CHAP
- Page 2440:
Click Next to display the dialog bo
- Page 2444:
for the first line to obtain inform
- Page 2448:
Figure 44.6 Choose JSF Managed Bean
- Page 2452:
You can display current time by inv
- Page 2456:
JSF Tag h:form h:panelGroup h:panel
- Page 2460:
Remarks: The t
- Page 2464:
The h:selectManyCheckbox element is
- Page 2468:
for (String s: minor) { allMinor +=
- Page 2472:
Figure 44.13 The user input i
- Page 2476:
package jsf2demo; import javax
- Page 2480:
The action attribute for the Add bu
- Page 2484:
The getResponse method converts gue
- Page 2488:
Figure 44.16 The correct input valu
- Page 2492:
Listing 44.12 ValidateForm.java pa
- Page 2496:
Step 3. Create a cascading style sh
- Page 2500:
} } ex.printStackTrace(); public St
- Page 2504:
Birth Date #{student.birthDate} D
- Page 2508:
Figure 44.22 This page lets the use
- Page 2512:
value="#{addressRegistration.requ
- Page 2516:
public String getTelephone() { retu
- Page 2520:
} status = ex.getMessage(); } retur
- Page 2524:
Section 44.6 44.13 What is a JSF se
- Page 2528:
44.5* (Addition quiz) Write a JSF p
- Page 2532:
Figure 44.30 44.10* The web page le
- Page 2536:
***This is a bonus Web chapter CHAP
- Page 2540:
In the New Project dialog box, choo
- Page 2544:
http://localhost:8080/WebServicePro
- Page 2548:
Right-click the ScoreWebServiceClie
- Page 2552:
private JTextField jtfName = new JT
- Page 2556:
specified arguments (if any) and se
- Page 2560:
eturn address; } else return null;
- Page 2564:
Figure 45.13 The Store button store
- Page 2568:
Last Name * First Name * &nb
- Page 2572:
questions for the client and grades
- Page 2576:
Assume that five True/False questio
- Page 2580:
Out of questions, correct
- Page 2584:
45.7 Can you test a Web service fro
- Page 2588:
***This is a bonus Web chapter CHAP
- Page 2592:
Server stub: An object that resides
- Page 2596:
java.rmi.registry.Registry +bind(na
- Page 2600:
2. Create a server implementation n
- Page 2604:
import java.rmi.registry.Registry;
- Page 2608:
5.4. Run the client StudentServerIn
- Page 2612:
2. Create a new server implementati
- Page 2616:
import java.rmi.registry.*; public
- Page 2620:
public interface CallBack extends R
- Page 2624:
import java.rmi.server.*; import ja
- Page 2628:
} return false; /** Check if the bo
- Page 2632:
} // Create cells and place cells i
- Page 2636:
} } } getSize().height - 20); } /**
- Page 2640:
Chapter Summary 1. RMI is a high-le
- Page 2644:
***This is a bonus Web chapter CHAP
- Page 2648:
Run from www.cs.armstrong.edu/liang
- Page 2652:
Listing 47.1 Searching an Element i
- Page 2656:
p0 e1 p1 e0 e e2 c0 c1 c2 rightChil
- Page 2660:
Case 1: u is a leaf 3-node or 4-nod
- Page 2664:
Locate the rightmost node in the le
- Page 2668:
16 27 27 34 16 34 3 15 24 25 29 50
- Page 2672:
import java.u
- Page 2676:
} } else { Tree24Node v = new Tree2
- Page 2680:
} } // Get the path that leads to e
- Page 2684:
} // Adjust child links for nonleaf
- Page 2688:
or 3-node, invoke insert23(e, right
- Page 2692:
22 System.out.print("\nAfter insert
- Page 2696:
20 15 24 27 50 3 16 22 23 25 29 60
- Page 2700:
for data stored on secondary storag
- Page 2704:
(a) Before a fusion is performed (b
- Page 2708:
Show the change of a 2-4 tree when
- Page 2712:
***This is a bonus Web chapter CHAP
- Page 2716:
ed node 27 is merged to its parent
- Page 2720:
Figure 48.4 The RBTree class extend
- Page 2724:
w 40 u y3 v 20 30 u x v 20 u 30 40
- Page 2728:
public boolean insert(E
- Page 2732:
sibling of v) (lines 32-33). If x i
- Page 2736:
If u is black and childOfu is red,
- Page 2740:
parent y y1 y u y1 parent childOfu
- Page 2744:
parent y y parent y2 childOfu is do
- Page 2748:
} fixDoubleBlack(grandparentOfu, pa
- Page 2752:
After deleting 25, the new tree is
- Page 2756:
import java.util.Arr
- Page 2760:
} else { // Case 2: v's sibling x i
- Page 2764:
(RBTreeNode)(parent.left) : (RBTree
- Page 2768:
} if (root == null) return; System.
- Page 2772:
Otherwise, y is red. In this case,
- Page 2776:
50 (black) The number of nodes is 7
- Page 2780:
public class TreePerformanceTest
- Page 2784:
7. If the external node to be delet
- Page 2788:
***This is a bonus Web chapter CHAP
- Page 2792:
Java 2D provides facilities to cons
- Page 2796:
ectangular frame. Figure 49.3 shows
- Page 2800:
import java.awt.*; import j
- Page 2804:
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 8 9
- Page 2808:
import java.awt.*; import java.a
- Page 2812:
Figure 49.12 After scaling is appli
- Page 2816:
} } } BasicStroke.JOIN_BEVEL)); g2d
- Page 2820:
A TexturePaint is specified by an i
- Page 2824:
The statement in lines 36-37 Textur
- Page 2828:
} } } // Draw a quadratic curve g2d
- Page 2832:
class ShapePanel extends JPanel { p
- Page 2836:
} Graphics2D g2d = (Graphics2D)g; /
- Page 2840:
import java.awt.*; import jav
- Page 2844:
10. You can specify the width of th
- Page 2848:
(a) (b) Figure 49.27 (c) (d) (e) (a
- Page 2852:
49.11* (Plot the log, n, nlogn, and
- Page 2856:
***This is a bonus Web chapter CHAP
- Page 2860:
The JUnit test runner displays the
- Page 2864:
Figure 50.3 The test report is disp
- Page 2868:
** Construct a loan with specified
- Page 2872:
Figure 50.6 A new project named cha
- Page 2876:
Figure 50.9 The Create Tests dialog
- Page 2880:
Figure 50.12 The New Java Project d
- Page 2884:
Figure 50.14 The Loan class is crea
- Page 2888:
Figure 50.17 The test report is dis