- Page 2: ONLINE ACCESS Thank you for purchas
- Page 6: This page intentionally left blank
- Page 12: This book is dedicated to Professor
- Page 16: PREFACE Dear Reader, Many of you ha
- Page 20: Preface ix ■ ■ ■ ■ The Chap
- Page 24: Online Practice and Assessment with
- Page 28: Preface xiii ■ ■ Trace programs
- Page 32: BRIEF CONTENTS 1 Introduction to Co
- Page 36: Contents xvii Chapter 3 Selections
- Page 40: Contents xix 8.9 Data Field Encapsu
- Page 44: Contents xxi 14.6 When to Use Excep
- Page 48: Contents xxiii APPENDIXES Appendix
- Page 52: VideoNotes xxv Chapter 9 Chapter 10
- Page 56: CHAPTER 1 INTRODUCTION TO COMPUTERS
- Page 60:
1.2 What Is a Computer? 3 CPU Memor
- Page 64:
1.2 What Is a Computer? 5 A compute
- Page 68:
USB Flash Drives Universal serial b
- Page 72:
1.3 Programming Languages 9 Network
- Page 76:
1.3 Programming Languages 11 TABLE
- Page 80:
1.5 Java, the World Wide Web, and B
- Page 84:
1.5 Java, the World Wide Web, and B
- Page 88:
1.7 A Simple Java Program 17 LISTIN
- Page 92:
1.8 Creating, Compiling, and Execut
- Page 96:
1.8 Creating, Compiling, and Execut
- Page 100:
1.9 Displaying Text in a Message Di
- Page 104:
1.10 Programming Style and Document
- Page 108:
1.11 Programming Errors 27 Tip If y
- Page 112:
Chapter Summary 29 logic error 27 l
- Page 116:
34. There are two types of import s
- Page 120:
CHAPTER 2 ELEMENTARY PROGRAMMING Ob
- Page 124:
2.2 Writing a Simple Program 35 } }
- Page 128:
2.3 Reading Input from the Console
- Page 132:
More details on objects will be int
- Page 136:
2.5 Variables 41 the program in Lis
- Page 140:
2.7 Named Constants 43 which is equ
- Page 144:
TABLE 2.2 Numeric Data Types Name R
- Page 148:
The program in Listing 2.4 obtains
- Page 152:
An integer literal is assumed to be
- Page 156:
2.12 Case Study: Displaying the Cur
- Page 160:
2.13 Augmented Assignment Operators
- Page 164:
Here are additional examples to ill
- Page 168:
Note To assign a variable of the in
- Page 172:
totalPayment = monthlyPayment * num
- Page 176:
2.16 Software Development Process 6
- Page 180:
2.17 Character Data Type and Operat
- Page 184:
int j = 2 + 'a'; // (int)'a' is 97
- Page 188:
2.17 Character Data Type and Operat
- Page 192:
2.18 The String Type 69 To read a s
- Page 196:
2.19.2 Using Input Dialog Boxes Hav
- Page 200:
Chapter Summary 73 scope of a varia
- Page 204:
Programming Exercises 75 Enter a de
- Page 208:
Programming Exercises 77 Enter the
- Page 212:
Programming Exercises 79 2.18 (Prin
- Page 216:
CHAPTER 3 SELECTIONS Objectives ■
- Page 220:
3.2 boolean Data Type 83 A variable
- Page 224:
3.3 if Statements 85 booleanexpress
- Page 228:
3.4 Case Study: Guessing Birthdays
- Page 232:
3.5 Two-Way if-else Statements 89 l
- Page 236:
3.6 Nested if and Multi-Way if-else
- Page 240:
3.7 Common Errors in Selection Stat
- Page 244:
3.7 Common Errors in Selection Stat
- Page 248:
3.9 Case Study: Computing Body Mass
- Page 252:
The constants KILOGRAMS_PER_POUND a
- Page 256:
3.11 Logical Operators 101 (0-singl
- Page 260:
3.11 Logical Operators 103 TABLE 3.
- Page 264:
3.21 Assume that x and y are int ty
- Page 268:
3.13 Case Study: Lottery 107 6 int
- Page 272:
This statement checks to see whethe
- Page 276:
3.15 Conditional Expressions 111 En
- Page 280:
3.16 Formatting Console Output 113
- Page 284:
3.17 Operator Precedence and Associ
- Page 288:
3.18 Confirmation Dialogs 117 3.39
- Page 292:
3.19 Debugging 119 (a) (b) (c) (d)
- Page 296:
6. The various if statements all ma
- Page 300:
Programming Exercises 123 Enter tod
- Page 304:
*3.20 (Science: wind-chill temperat
- Page 308:
Programming Exercises 127 (x2, y2)
- Page 312:
Programming Exercises 129 r1 r1 r2
- Page 316:
Programming Exercises 131 Enter wei
- Page 320:
CHAPTER 4 LOOPS Objectives ■ To w
- Page 324:
4.2 The while Loop 135 count = 0; l
- Page 328:
The loop in lines 15-19 repeatedly
- Page 332:
4.2 The while Loop 139 20 System.ou
- Page 336:
4.2 The while Loop 141 What is 9 -
- Page 340:
4.2 The while Loop 143 Variable ite
- Page 344:
4.3 The do-while Loop 145 Statement
- Page 348:
4.4 The for Loop 147 In general, th
- Page 352:
4.4 The for Loop 149 4.8 Do the fol
- Page 356:
These errors often occur when you u
- Page 360:
4.6 Nested Loops 153 Note Be aware
- Page 364:
4.8 Case Studies 155 } sum += curre
- Page 368:
This revision is wrong. Can you fin
- Page 372:
4.9 Keywords break and continue 159
- Page 376:
System.out.println("The smallest fa
- Page 380:
4.10 Case Study: Displaying Prime N
- Page 384:
Key Terms 165 6 7 // Keep reading d
- Page 388:
Sections 4.2-4.7 *4.1 (Count positi
- Page 392:
Programming Exercises 169 Enter the
- Page 396:
Programming Exercises 171 **4.25 (C
- Page 400:
**4.33 (Perfect number) A positive
- Page 404:
Programming Exercises 175 Enter an
- Page 408:
CHAPTER 5 METHODS Objectives ■ To
- Page 412:
Let’s look at a method defined to
- Page 416:
5.3 Calling a Method 181 The maximu
- Page 420:
5.4 void Method Example 183 5.4 voi
- Page 424:
5.4 void Method Example 185 5.1 Wha
- Page 428:
Listing 5.5 gives another program t
- Page 432:
5.6 Modularizing Code 189 public cl
- Page 436:
5.7 Case Study: Converting Decimals
- Page 440:
5.8 Overloading Methods 193 Enter a
- Page 444:
Can you invoke the max method with
- Page 448:
5.10 The Math Class 197 It is fine
- Page 452:
5.10 The Math Class 199 Math.sqrt(4
- Page 456:
5.11 Case Study: Generating Random
- Page 460:
5.12 Method Abstraction and Stepwis
- Page 464:
5.12 Method Abstraction and Stepwis
- Page 468:
** A stub for getMonthName may look
- Page 472:
5.12 Method Abstraction and Stepwis
- Page 476:
Test Questions 211 CHAPTER SUMMARY
- Page 480:
Programming Exercises 213 The metho
- Page 484:
Programming Exercises 215 *5.14 (Es
- Page 488:
**5.22 (Math: approximate the squar
- Page 492:
Programming Exercises 219 You rolle
- Page 496:
**5.34 (Print calendar) Programming
- Page 500:
CHAPTER 6 SINGLE-DIMENSIONAL ARRAYS
- Page 504:
6.2 Array Basics 225 This section i
- Page 508:
6.2 Array Basics 227 After an array
- Page 512:
6.2 Array Basics 229 myList[i], ran
- Page 516:
e. Write a loop that finds the mini
- Page 520:
6.3 Case Study: Lotto Numbers 233 1
- Page 524:
6.4 Case Study: Deck of Cards 235 0
- Page 528:
There are three ways to copy arrays
- Page 532:
6.6 Passing Arrays to Methods 239 S
- Page 536:
6.8 Case Study: Counting the Occurr
- Page 540:
6.8 Case Study: Counting the Occurr
- Page 544:
6.10 Searching Arrays 245 10 return
- Page 548:
6.10 Searching Arrays 247 key is 11
- Page 552:
6.11 Sorting Arrays 249 6.11.1 Sele
- Page 556:
6.11 Sorting Arrays 251 Step 1: Ini
- Page 560:
6.12 The Arrays Class 253 System.ou
- Page 564:
12. The insertion-sort algorithm so
- Page 568:
Write a test program that prompts t
- Page 572:
Programming Exercises 259 (a) (b) (
- Page 576:
Programming Exercises 261 Enter lis
- Page 580:
CHAPTER 7 MULTIDIMENSIONAL ARRAYS O
- Page 584:
7.2 Two-Dimensional Array Basics 26
- Page 588:
7.2 Can the rows in a two-dimension
- Page 592:
7.4 Passing Two-Dimensional Arrays
- Page 596:
7.5 Case Study: Grading a Multiple-
- Page 600:
7.6 Case Study: Finding the Closest
- Page 604:
■ Check each cell. Each cell must
- Page 608:
7.8 Multidimensional Arrays 277 Wit
- Page 612:
18 data[day - 1][hour - 1][1] = hum
- Page 616:
CHAPTER SUMMARY 1. A two-dimensiona
- Page 620:
**7.6 (Algebra: multiply two matric
- Page 624:
Each state can also be represented
- Page 628:
The method performs a primary sort
- Page 632:
Programming Exercises 289 | | | | |
- Page 636:
Write a test program that prompts t
- Page 640:
Programming Exercises 293 v 2 (x2,
- Page 644:
CHAPTER 8 OBJECTS AND CLASSES Objec
- Page 648:
8.2 Defining Classes for Objects 29
- Page 652:
8.3 Example: Defining Classes and C
- Page 656:
42 /** Return the perimeter of this
- Page 660:
8.4 Constructing Objects Using Cons
- Page 664:
8.5 Accessing Objects via Reference
- Page 668:
8.5 Accessing Objects via Reference
- Page 672:
8.6 Using Classes from the Java Lib
- Page 676:
8.6 Using Classes from the Java Lib
- Page 680:
8.7 Static Variables, Constants, an
- Page 684:
8.7 Static Variables, Constants, an
- Page 688:
8.8 Visibility Modifiers 317 public
- Page 692:
8.9 Data Field Encapsulation 319 pu
- Page 696:
8.9 Data Field Encapsulation 321 16
- Page 700:
The program in Listing 8.11 demonst
- Page 704:
8.10 Passing Objects to Methods 325
- Page 708:
8.11 Array of Objects 327 circleArr
- Page 712:
Chapter Summary 329 instance 296 in
- Page 716:
*8.4 (Use the Random class) Write a
- Page 720:
■ Three get methods for a, b, and
- Page 724:
CHAPTER 9 STRINGS Objectives ■ To
- Page 728:
"HTML" and assigns its reference to
- Page 732:
compareToIgnoreCase methods ignore
- Page 736:
9.2 The String Class 341 Note If be
- Page 740:
9.2 The String Class 343 java.lang.
- Page 744:
9.2 The String Class 345 is equival
- Page 748:
4 public void Test(String s) { 5 te
- Page 752:
9.4 Case Study: Converting Hexadeci
- Page 756:
9.5 The Character Class 351 charObj
- Page 760:
9.6 The StringBuilder and StringBuf
- Page 764:
9.6 The StringBuilder and StringBuf
- Page 768:
9.6 The StringBuilder and StringBuf
- Page 772:
9.7.1 Passing Strings to the main M
- Page 776:
The expression is passed as a strin
- Page 780:
9.4 (Occurrences of a specified cha
- Page 784:
second program passes an unspecifie
- Page 788:
Programming Exercises 367 /** Retur
- Page 792:
CHAPTER 10 THINKING IN OBJECTS Obje
- Page 796:
public class Test { public static v
- Page 800:
10.4 The this Reference 373 10.4 Th
- Page 804:
10.5 Class Abstraction and Encapsul
- Page 808:
10.5 Class Abstraction and Encapsul
- Page 812:
From a class developer’s perspect
- Page 816:
10.6 Object-Oriented Thinking 381 7
- Page 820:
An aggregation relationship is usua
- Page 824:
10.8 Case Study: Designing the Cour
- Page 828:
10.9 Case Study: Designing a Class
- Page 832:
10.10 Case Study: Designing the Gue
- Page 836:
10.11 Class Design Guidelines 391 2
- Page 840:
10.12 Processing Primitive Data Typ
- Page 844:
new Double("12.4").compareTo(new Do
- Page 848:
10.14 The BigInteger and BigDecimal
- Page 852:
Programming Exercises 399 KEY TERMS
- Page 856:
■ A method named distance that re
- Page 860:
Programming Exercises 403 TABLE 10.
- Page 864:
*10.13 (Geometry: the MyRectangle2D
- Page 868:
CHAPTER 11 INHERITANCE AND POLYMORP
- Page 872:
11.2 Superclasses and Subclasses 40
- Page 876:
11.2 Superclasses and Subclasses 41
- Page 880:
11.2 Superclasses and Subclasses 41
- Page 884:
11.3 Using the super Keyword 415 Th
- Page 888:
Since no constructor is explicitly
- Page 892:
Let us use an example to show the d
- 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