0% found this document useful (0 votes)
28 views125 pages

Java Programming 5th Edition Joyce Farrell Full Access

Study resource: Java Programming 5th Edition Joyce FarrellGet it instantly. Built for academic development with logical flow and educational clarity.

Uploaded by

aparnamo3389
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views125 pages

Java Programming 5th Edition Joyce Farrell Full Access

Study resource: Java Programming 5th Edition Joyce FarrellGet it instantly. Built for academic development with logical flow and educational clarity.

Uploaded by

aparnamo3389
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 125

Java Programming 5th Edition Joyce Farrell pdf

download

https://ebookname.com/product/java-programming-5th-edition-joyce-
farrell/

★★★★★
4.8 out of 5.0 (30 reviews )

Instant PDF Download

ebookname.com
Java Programming 5th Edition Joyce Farrell

EBOOK

Available Formats

■ PDF eBook Study Guide Ebook

EXCLUSIVE 2025 ACADEMIC EDITION – LIMITED RELEASE

Available Instantly Access Library


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Programming Logic and Design Comprehensive 6th Edition


Joyce Farrell

https://ebookname.com/product/programming-logic-and-design-
comprehensive-6th-edition-joyce-farrell/

ebookname.com

Object Oriented Programming Using C Fourth Edition Joyce


Farrell

https://ebookname.com/product/object-oriented-programming-using-c-
fourth-edition-joyce-farrell/

ebookname.com

Just Enough Programming Logic and Design 1st Edition Joyce


Farrell

https://ebookname.com/product/just-enough-programming-logic-and-
design-1st-edition-joyce-farrell/

ebookname.com

Space Systems Failures Disasters and Rescues of Satellites


Rockets and Space Probes 1st Edition David M. Harland

https://ebookname.com/product/space-systems-failures-disasters-and-
rescues-of-satellites-rockets-and-space-probes-1st-edition-david-m-
harland/
ebookname.com
Data Gathering Analysis and Protection of Privacy Through
Randomized Response Techniques Qualitative and
Quantitative Human Traits 1st Edition Arijit Chaudhuri
https://ebookname.com/product/data-gathering-analysis-and-protection-
of-privacy-through-randomized-response-techniques-qualitative-and-
quantitative-human-traits-1st-edition-arijit-chaudhuri/
ebookname.com

Essentials of Business Communication Book Only Eighth


Edition Mary Ellen Guffey

https://ebookname.com/product/essentials-of-business-communication-
book-only-eighth-edition-mary-ellen-guffey/

ebookname.com

Nationalism in Europe since 1945 1st Edition André Gerrits

https://ebookname.com/product/nationalism-in-europe-since-1945-1st-
edition-andre-gerrits/

ebookname.com

Beginning XML 5th Edition Joe Fawcett

https://ebookname.com/product/beginning-xml-5th-edition-joe-fawcett/

ebookname.com

Student Solutions Manual for Brase Brase s Understanding


Basic Statistics Brief 4th 4th Edition Charles Henry Brase

https://ebookname.com/product/student-solutions-manual-for-brase-
brase-s-understanding-basic-statistics-brief-4th-4th-edition-charles-
henry-brase/
ebookname.com
Emergency Response Guidebook A Guidebook for First
Repsponders During the Initial Phase of a Dangerous Goods
Hazardous Materials Transportation Inc 1st Edition Us
Deparment Of Transportation
https://ebookname.com/product/emergency-response-guidebook-a-
guidebook-for-first-repsponders-during-the-initial-phase-of-a-
dangerous-goods-hazardous-materials-transportation-inc-1st-edition-us-
deparment-of-transportation/
ebookname.com
Java Programming
Fifth Edition
Joyce Farrell

Australia • Brazil • Japan • Korea • Mexico • Singapore • Spain • United Kingdom • United States
Java Programming, Fifth Edition © 2010 Course Technology, Cengage Learning
Joyce Farrell
ALL RIGHTS RESERVED. No part of this work covered by the copyright herein
Executive Editor: Marie Lee may be reproduced, transmitted, stored, or used in any form or by any means—
graphic, electronic, or mechanical, including but not limited to photocopying,
Acquisitions Editor: Amy Jollymore
recording, scanning, digitizing, taping, Web distribution, information networks, or
Managing Editor: Tricia Coia information storage and retrieval systems, except as permitted under Section
Development Editor: Dan Seiter 107 or 108 of the 1976 United States Copyright Act—without the prior written
permission of the publisher.
Editorial Assistant:
Julia Leroux-Lindsey
For product information and technology assistance, contact us at
Marketing Manager: Bryant Chrzan Cengage Learning Customer & Sales Support, 1-800-354-9706
Content Project Manager: For permission to use material from this text or product,
Heather Furrow submit all requests online at www.cengage.com/permissions
Art Director: Marissa Falco Further permissions questions can be e-mailed to
permissionrequest@cengage.com
Cover Designer: Bruce Bond
Cover Photo: TBD
Microsoft® is a registered trademark of the Microsoft Corporation.
Manufacturing Coordinator:
Julio Esperas ISBN-13: 978-0-3245-9951-0

Proofreader: Andrea Schein ISBN-10: 0-3245-9951-X


Indexer: Elizabeth Cunningham
Course Technology
Compositor: International Typesetting 25 Thomson Place
and Composition Boston, MA 02210
USA

Cengage Learning is a leading provider of customized learning solutions with


office locations around the globe, including Singapore, the United Kingdom,
Australia, Mexico, Brazil, and Japan. Locate your local office at:
www.international.cengage.com/region

Cengage Learning products are represented in Canada by Nelson Education, Ltd.

To learn more about Course Technology, visit


www.cengage.com/coursetechnology
Purchase any of our products at your local bookstore or at our preferred online
store www.ichapters.com
Some of the product names and company names used in this book have been
used for identification purposes only and may be trademarks or registered
trademarks of their respective manufacturers and sellers.
Course Technology, a part of Cengage Learning, reserves the right to revise this
publication and make changes from time to time in its content without notice.

Printed in Canada
1 2 3 4 5 6 7 12 11 10 09 08
BRIEF CONTENTS
PREFACE xix
READ THIS BEFORE YOU BEGIN xxv

CHAPTER 1 CREATING YOUR FIRST JAVA CLASSES 1


CHAPTER 2 USING DATA WITHIN A PROGRAM 43
CHAPTER 3 USING METHODS, CLASSES, AND OBJECTS 89
CHAPTER 4 MORE OBJECT CONCEPTS 135
CHAPTER 5 MAKING DECISIONS 187
CHAPTER 6 LOOPING 233
CHAPTER 7 CHARACTERS, STRINGS, AND THE STRINGBUILDER 273
CHAPTER 8 ARRAYS 309
CHAPTER 9 INTRODUCTION TO INHERITANCE 369
CHAPTER 10 ADVANCED INHERITANCE CONCEPTS 413
CHAPTER 11 EXCEPTION HANDLING 461
CHAPTER 12 FILE INPUT AND OUTPUT 525
CHAPTER 13 INTRODUCTION TO SWING COMPONENTS 587
CHAPTER 14 ADVANCED GUI TOPICS 641
CHAPTER 15 GRAPHICS 709
CHAPTER 16 APPLETS, IMAGES, AND SOUND 763
APPENDIX A WORKING WITH THE JAVA PLATFORM 807
APPENDIX B LEARNING ABOUT ASCII AND UNICODE 815
APPENDIX C FORMATTING OUTPUT 821
APPENDIX D GENERATING RANDOM NUMBERS 833
APPENDIX E JAVADOC 839
GLOSSARY 847
INDEX 867

iii
This page intentionally left blank
CONTENTS
PREFACE xix
READ THIS BEFORE YOU BEGIN xxv

CHAPTER 1 CREATING YOUR FIRST JAVA CLASSES 1


LEARNING ABOUT PROGRAMMING 2
INTRODUCING OBJECT-ORIENTED PROGRAMMING CONCEPTS 4
Procedural Programming 4
Object-Oriented Programming 4
Understanding Objects, Classes, and Encapsulation 5
Understanding Inheritance and Polymorphism 7
LEARNING ABOUT JAVA 8
Java Program Types 9
ANALYZING A JAVA APPLICATION THAT USES CONSOLE OUTPUT 10
Understanding the Statement That Prints the Output 10
Understanding the First Class 11
Understanding the main() Method 14
ADDING COMMENTS TO A JAVA CLASS 16
SAVING, COMPILING, RUNNING, AND MODIFYING A JAVA APPLICATION 18
Saving a Java Class 18
Compiling a Java Class 18
Running a Java Application 19
Modifying a Java Class 19
CREATING A JAVA APPLICATION USING GUI OUTPUT 21
CORRECTING ERRORS AND FINDING HELP 23
YOU DO IT 26
Your First Application 26
Adding Comments to a Class 27
Modifying a Class 28
Creating a Dialog Box 29
DON’T DO IT 30
KEY TERMS 31
CHAPTER SUMMARY 34
REVIEW QUESTIONS 35
EXERCISES 37

v
CONTENTS

DEBUGGING EXERCISES 39
GAME ZONE 39
TOUGH QUESTIONS 40
UP FOR DISCUSSION 41

CHAPTER 2 USING DATA WITHIN A PROGRAM 43


USING CONSTANTS AND VARIABLES 44
Declaring Variables 45
Declaring Named Constants 46
Pitfall: Forgetting That a Variable Holds One Value at a Time 48
LEARNING ABOUT THE int DATA TYPE 48
DISPLAYING DATA 50
WRITING ARITHMETIC STATEMENTS 51
Writing Arithmetic Statements Efficiently 53
USING THE BOOLEAN DATA TYPE 54
LEARNING ABOUT FLOATING-POINT DATA TYPES 55
UNDERSTANDING NUMERIC-TYPE CONVERSION 56
WORKING WITH THE char DATA TYPE 58
USING THE Scanner CLASS FOR KEYBOARD INPUT 61
Pitfall: Using nextLine() Following One of the Other Scanner
Input Methods 63
USING THE JOptionPane CLASS FOR GUI INPUT 66
Using Input Dialog Boxes 66
Using Confirm Dialog Boxes 70
YOU DO IT 72
Working with Numeric Values 72
Accepting User Data 73
Performing Arithmetic 74
Experimenting with Java Programs 75
DON’T DO IT 76
KEY TERMS 77
CHAPTER SUMMARY 80
REVIEW QUESTIONS 81
EXERCISES 83
DEBUGGING EXERCISES 86
GAME ZONE 86
TOUGH QUESTIONS 86
UP FOR DISCUSSION 87

vi
CONTENTS

CHAPTER 3 USING METHODS, CLASSES, AND OBJECTS 89


CREATING METHODS WITH ZERO, ONE, AND MULTIPLE PARAMETERS 90
Creating Methods That Require a Single Parameter 94
Creating Methods That Require Multiple Parameters 97
CREATING METHODS THAT RETURN VALUES 99
Calling a Method from Another Method 101
LEARNING ABOUT CLASS CONCEPTS 102
CREATING A CLASS 104
CREATING INSTANCE METHODS IN A CLASS 106
DECLARING OBJECTS AND USING THEIR METHODS 109
Understanding Data Hiding 110
ORGANIZING CLASSES 112
AN INTRODUCTION TO USING CONSTRUCTORS 114
UNDERSTANDING THAT CLASSES ARE DATA TYPES 116
YOU DO IT 118
Creating a Static Method That Requires No Arguments and Returns No Values 118
Calling a Static Method from Another Class 119
Creating a Static Method That Accepts Arguments and Returns Values 120
Creating a Class That Contains Instance Fields and Methods 122
Creating a Class That Instantiates Objects of Another Class 123
Adding a Constructor to a Class 124
Creating a More Complete Class 124
DON’T DO IT 125
KEY TERMS 125
CHAPTER SUMMARY 127
REVIEW QUESTIONS 128
EXERCISES 131
DEBUGGING EXERCISES 133
GAME ZONE 133
TOUGH QUESTIONS 134
UP FOR DISCUSSION 134

CHAPTER 4 MORE OBJECT CONCEPTS 135


UNDERSTANDING BLOCKS AND SCOPE 136
OVERLOADING A METHOD 142
LEARNING ABOUT AMBIGUITY 144
SENDING ARGUMENTS TO CONSTRUCTORS 147
OVERLOADING CONSTRUCTORS 148

vii
CONTENTS

LEARNING ABOUT THE this REFERENCE 149


Using the this Reference to Make Overloaded Constructors More Efficient 152
USING static VARIABLES 154
USING CONSTANT FIELDS 156
USING AUTOMATICALLY IMPORTED, PREWRITTEN CONSTANTS AND METHODS 157
USING AN EXPLICITLY IMPORTED PREWRITTEN CLASS AND ITS METHODS 160
UNDERSTANDING COMPOSITION 164
A BRIEF LOOK AT NESTED AND INNER CLASSES 166
YOU DO IT 168
Demonstrating Scope 168
Overloading Methods 170
Creating a Constructor That Requires an Argument 171
Using an Explicitly Imported Prewritten Class 172
Creating an Interactive Application with a Timer 174
DON’T DO IT 176
KEY TERMS 176
CHAPTER SUMMARY 177
REVIEW QUESTIONS 178
EXERCISES 181
DEBUGGING EXERCISES 184
GAME ZONE 184
TOUGH QUESTIONS 185
UP FOR DISCUSSION 185

CHAPTER 5 MAKING DECISIONS 187


UNDERSTANDING DECISION MAKING 188
MAKING DECISIONS WITH THE if AND if...else STRUCTURES 190
Pitfall: Misplacing a Semicolon in an if Statement 191
Pitfall: Using the Assignment Operator Instead of the Equivalency Operator 192
Pitfall: Attempting to Compare Objects Using the Relational Operators 192
The if...else Structure 193
USING MULTIPLE STATEMENTS IN AN if OR if...else STRUCTURE 194
NESTING if AND if...else STATEMENTS 197
USING LOGICAL AND and OR OPERATORS 199
MAKING ACCURATE AND EFFICIENT DECISIONS 202
Using AND and OR Appropriately 205
USING THE switch STATEMENT 206
USING THE CONDITIONAL AND NOT OPERATORS 209
Using the NOT Operator 210
UNDERSTANDING PRECEDENCE 211

viii
Visit https://ebookname.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
CONTENTS

YOU DO IT 213
Using an if...else 213
Creating an Event Class to Use in a Decision-Making Application 215
Writing an Application that Uses the Event class 216
Using the switch Statement 218
DON’T DO IT 219
KEY TERMS 220
CHAPTER SUMMARY 221
REVIEW QUESTIONS 221
EXERCISES 224
DEBUGGING EXERCISES 229
GAME ZONE 229
TOUGH QUESTIONS 231
UP FOR DISCUSSION 232

CHAPTER 6 LOOPING 233


LEARNING ABOUT THE LOOP STRUCTURE 234
USING A while LOOP TO CREATE A DEFINITE LOOP 235
USING A while LOOP TO CREATE AN INDEFINITE LOOP 239
USING SHORTCUT ARITHMETIC OPERATORS 243
USING A for LOOP 246
LEARNING HOW AND WHEN TO USE A do...while LOOP 248
LEARNING ABOUT NESTED LOOPS 250
IMPROVING LOOP PERFORMANCE 252
Avoiding Unnecessary Operations 253
Considering the Order of Evaluation of Short-Circuit Operators 253
Comparing to Zero 254
Employing Loop Fusion 255
YOU DO IT 256
Writing a Loop to Validate Data Entries 256
Working with Prefix and Postfix Increment Operators 257
Working with Definite Loops 259
Working with Nested Loops 260
DON’T DO IT 261
KEY TERMS 262
CHAPTER SUMMARY 263
REVIEW QUESTIONS 264
EXERCISES 267
DEBUGGING EXERCISES 269

ix
CONTENTS

GAME ZONE 269


TOUGH QUESTIONS 270
UP FOR DISCUSSION 271

CHAPTER 7 CHARACTERS, STRINGS, AND THE STRINGBUILDER 273


IDENTIFYING PROBLEMS THAT CAN OCCUR WHEN YOU MANIPULATE STRING DATA 274
MANIPULATING CHARACTERS 276
DECLARING A String OBJECT 278
COMPARING String VALUES 279
USING OTHER String METHODS 283
CONVERTING Strings TO NUMBERS 286
LEARNING ABOUT THE StringBuilder AND StringBuffer CLASSES 288
YOU DO IT 293
Using String Class Methods 293
Converting a String to an Integer 295
Using StringBuilder Methods 296
DON’T DO IT 297
KEY TERMS 297
CHAPTER SUMMARY 299
REVIEW QUESTIONS 300
EXERCISES 302
DEBUGGING EXERCISES 305
GAME ZONE 305
TOUGH QUESTIONS 307
UP FOR DISCUSSION 308

CHAPTER 8 ARRAYS 309


DECLARING AND INITIALIZING AN ARRAY 310
Initializing an Array 312
USING SUBSCRIPTS WITH AN ARRAY 313
DECLARING AN ARRAY OF OBJECTS 316
SEARCHING AN ARRAY FOR AN EXACT MATCH 318
SEARCHING AN ARRAY FOR A RANGE MATCH 321
PASSING ARRAYS TO AND RETURNING ARRAYS FROM METHODS 323
Returning an Array from a Method 326
MANIPULATING ARRAYS OF Strings 326
SORTING ARRAY ELEMENTS 328
Sorting Arrays of Objects 332

x
CONTENTS

USING TWO-DIMENSIONAL AND MULTIDIMENSIONAL ARRAYS 334


Using the length Field with a Two-Dimensional Array 336
Understanding Ragged Arrays 336
Using Multidimensional Arrays 336
USING THE Arrays CLASS 337
USING THE ArrayList CLASS 341
Understanding the Limitations of the ArrayList Class 343
YOU DO IT 344
Creating and Populating an Array 344
Initializing an Array 345
Using a for Loop to Access Array Elements 346
Creating Parallel Arrays to Eliminate Nested if Statements 346
Creating an Application with an Array of Objects 347
Creating an Interactive Application That Creates an Array of Objects 348
Passing an Array to a Method 350
Using Arrays Class Methods 351
DON’T DO IT 353
KEY TERMS 354
CHAPTER SUMMARY 355
REVIEW QUESTIONS 356
EXERCISES 359
DEBUGGING EXERCISES 363
GAME ZONE 363
TOUGH QUESTIONS 367
UP FOR DISCUSSION 367

CHAPTER 9 INTRODUCTION TO INHERITANCE 369


LEARNING ABOUT THE CONCEPT OF INHERITANCE 370
EXTENDING CLASSES 374
OVERRIDING SUPERCLASS METHODS 376
UNDERSTANDING HOW CONSTRUCTORS ARE CALLED DURING INHERITANCE 377
USING SUPERCLASS CONSTRUCTORS THAT REQUIRE ARGUMENTS 379
ACCESSING SUPERCLASS METHODS 380
Comparing this and super 382
LEARNING ABOUT INFORMATION HIDING 382
METHODS YOU CANNOT OVERRIDE 385
A Subclass Cannot Override static Methods in Its Superclass 385
A Subclass Cannot Override final Methods in Its Superclass 388
A Subclass Cannot Override Methods in a final Superclass 390

xi
CONTENTS

YOU DO IT 391
Creating a Superclass and an Application to Use It 391
Creating a Subclass and an Application to Use It 393
Creating a Subclass Method That Overrides a Superclass Method 395
Understanding the Role of Constructors in Inheritance 397
Inheritance When the Superclass Requires Constructor Arguments 398
Accessing an Overridden Superclass Method from Within a Subclass 401
DON’T DO IT 402
KEY TERMS 402
CHAPTER SUMMARY 403
REVIEW QUESTIONS 404
EXERCISES 407
DEBUGGING EXERCISES 410
GAME ZONE 410
TOUGH QUESTIONS 411
UP FOR DISCUSSION 412

CHAPTER 10 ADVANCED INHERITANCE CONCEPTS 413


CREATING AND USING ABSTRACT CLASSES 414
USING DYNAMIC METHOD BINDING 418
Using a Superclass as a Method Parameter Type 419
CREATING ARRAYS OF SUBCLASS OBJECTS 420
USING THE Object CLASS AND ITS METHODS 422
Using the toString() Method 423
Using the equals() Method 425
USING INHERITANCE TO ACHIEVE GOOD SOFTWARE DESIGN 428
CREATING AND USING INTERFACES 429
Creating Interfaces to Store Related Constants 434
CREATING AND USING PACKAGES 435
YOU DO IT 437
Creating an Abstract Class 437
Extending an Abstract Class 438
Extending an Abstract Class with a Second Subclass 440
Instantiating Objects from Subclasses 441
Using Object References 442
Overriding the Object Class equals() Method 444
Eliminating Duplicate User Entries 445
Creating a Package 446
DON’T DO IT 449
KEY TERMS 449

xii
CONTENTS

CHAPTER SUMMARY 450


REVIEW QUESTIONS 451
EXERCISES 454
DEBUGGING EXERCISES 457
GAME ZONE 458
TOUGH QUESTIONS 458
UP FOR DISCUSSION 458

CHAPTER 11 EXCEPTION HANDLING 461


LEARNING ABOUT EXCEPTIONS 462
TRYING CODE AND CATCHING Exceptions 467
THROWING AND CATCHING MULTIPLE Exceptions 471
USING THE Finally BLOCK 476
UNDERSTANDING THE ADVANTAGES OF EXCEPTION HANDLING 478
SPECIFYING THE Exceptions A METHOD CAN THROW 480
TRACING Exceptions THROUGH THE CALL STACK 486
CREATING YOUR OWN Exceptions 490
USING ASSERTIONS 493
YOU DO IT 498
Catching an Exception and Using getMessage() 498
Generating a NumberFormatException 500
Adding NumberFormatException Handling Capabilities
to an Application 500
Creating a Class That Automatically Throws Exceptions 501
Creating a Class That Passes on an Exception 502
Creating an Application That Can Catch Exceptions 504
Extending a Class That Throws Exceptions 506
Using the printStackTrace() Method 507
Creating an Exception Class 509
Using an Exception You Created 509
DON’T DO IT 513
KEY TERMS 513
CHAPTER SUMMARY 514
REVIEW QUESTIONS 515
EXERCISES 518
DEBUGGING EXERCISES 522
GAME ZONE 522
TOUGH QUESTIONS 523
UP FOR DISCUSSION 523

xiii
CONTENTS

CHAPTER 12 FILE INPUT AND OUTPUT 525


UNDERSTANDING COMPUTER FILES 526
USING THE File CLASS 527
UNDERSTANDING DATA FILE ORGANIZATION AND STREAMS 530
USING STREAMS 532
WRITING TO AND READING FROM A FILE 536
Reading from a File 538
WRITING FORMATTED FILE DATA 540
READING FORMATTED FILE DATA 543
USING A VARIABLE FILENAME 545
CREATING AND USING RANDOM ACCESS FILES 548
WRITING RECORDS TO A RANDOM ACCESS FILE 551
READING RECORDS FROM A RANDOM ACCESS FILE 556
Accessing a Random Access File Sequentially 556
Accessing a Random Access File Randomly 557
READING AND WRITING OBJECTS TO AND FROM FILES 559
YOU DO IT 563
Using the File Class to Examine File Status 563
Comparing Two File Dates 564
Using InputStream and OutputStream Objects 565
Writing to an Output File 568
Reading Data from a File 568
Creating a Class to Use in a File of Objects 569
Creating a Program that Writes Event Objects to a File 571
Creating a Program that Accesses Stored Event Object Data 572
DON’T DO IT 576
KEY TERMS 576
CHAPTER SUMMARY 578
REVIEW QUESTIONS 579
EXERCISES 581
DEBUGGING EXERCISES 584
GAME ZONE 584
TOUGH QUESTIONS 584
UP FOR DISCUSSION 585

CHAPTER 13 INTRODUCTION TO SWING COMPONENTS 587


UNDERSTANDING Swing COMPONENTS 588
USING THE JFrame CLASS 589
Customizing a JFrame’s Appearance 593

xiv
CONTENTS

USING A JLabel 594


Changing a JLabel’s Font 596
USING A LAYOUT MANAGER 598
EXTENDING THE JFrame CLASS 600
ADDING JTextFields, JBUTTONS, AND TOOL TIPS TO A JFrame 602
Adding JButtons 604
Using Tool Tips 606
LEARNING ABOUT EVENT-DRIVEN PROGRAMMING 607
Preparing Your Class to Accept Event Messages 607
Telling Your Class to Expect Events to Happen 608
Telling Your Class How to Respond to Events 608
Using the setEnabled() Method 611
UNDERSTANDING Swing EVENT LISTENERS 611
USING THE JCheckBox CLASS 614
USING THE ButtonGroup CLASS 618
USING THE JComboBox CLASS 619
YOU DO IT 621
Creating a JFrame 621
Ending an Application When a JFrame Closes 623
Adding Components to a JFrame 623
Adding Functionality to a JButton and a JTextField 625
Distinguishing Event Sources 626
Including JCheckBoxes in an Application 627
DON’T DO IT 630
KEY TERMS 631
CHAPTER SUMMARY 632
REVIEW QUESTIONS 634
EXERCISES 637
DEBUGGING EXERCISES 638
GAME ZONE 639
TOUGH QUESTIONS 640
UP FOR DISCUSSION 640

CHAPTER 14 ADVANCED GUI TOPICS 641


UNDERSTANDING THE CONTENT PANE 642
USING COLOR 647
LEARNING MORE ABOUT LAYOUT MANAGERS 648
Using BorderLayout 649
Using FlowLayout 651
Using GridLayout 653

xv
CONTENTS

Using CardLayout 655


Using Advanced Layout Managers 656
USING THE JPanel CLASS 657
CREATING JScrollPanes 664
A CLOSER LOOK AT EVENTS AND EVENT HANDLING 666
An Event-Handling Example: KeyListener 669
USING AWTEvent CLASS METHODS 671
Understanding x- and y-Coordinates 673
HANDLING MOUSE EVENTS 674
USING MENUS 680
Using JCheckBoxMenuItem and JRadioButtonMenuItem Objects 683
Using addSeparator() 684
Using setMnemonic() 685
YOU DO IT 686
Using BorderLayout 686
Using Fewer than Five Components with the BorderLayout Manager 687
Using FlowLayout 688
Using GridLayout 689
Using CardLayout 690
Viewing All the Cards in CardLayout 690
Using a Menu Bar and JPanels 691
DON’T DO IT 696
KEY TERMS 696
CHAPTER SUMMARY 698
REVIEW QUESTIONS 699
EXERCISES 702
DEBUGGING EXERCISES 703
GAME ZONE 704
TOUGH QUESTIONS 708
UP FOR DISCUSSION 708

CHAPTER 15 GRAPHICS 709


LEARNING ABOUT THE paint() AND repaint() METHODS 710
Using the setLocation() Method 712
USING THE drawString() METHOD 714
Using the setFont() and setColor() Methods 715
Using Color 716
CREATING Graphics AND Graphics2D OBJECTS 717

xvi
CONTENTS

DRAWING LINES AND SHAPES 718


Drawing Ovals 720
Drawing Arcs 721
Creating Shadowed Rectangles 722
Creating Polygons 723
Copying an Area 725
LEARNING MORE ABOUT FONTS AND METHODS YOU CAN USE WITH THEM 726
Discovering Screen Statistics Using the Toolkit Class 728
Discovering Font Statistics 729
DRAWING WITH JAVA 2D GRAPHICS 731
Specifying the Rendering Attributes 731
Setting a Drawing Stroke 733
Creating Objects to Draw 734
YOU DO IT 736
Using the drawString() Method 736
Using Fonts and Colors 737
Creating Your Own Graphics Object 738
Examining Screen Coordinates 739
Creating a Drawing 740
Copying an Area 741
Using FontMetrics Methods to Compare Fonts 742
Using FontMetrics Methods to Place a Border Around a String 745
Using Drawing Strokes 746
Working with Shapes 748
DON’T DO IT 749
KEY TERMS 749
CHAPTER SUMMARY 751
REVIEW QUESTIONS 752
EXERCISES 755
DEBUGGING EXERCISES 758
GAME ZONE 758
TOUGH QUESTIONS 761
UP FOR DISCUSSION 761

CHAPTER 16 APPLETS, IMAGES, AND SOUND 763


INTRODUCING APPLETS 764
Understanding the JApplet Class 765
Running an Applet 765
WRITING AN HTML DOCUMENT TO HOST AN APPLET 766
CREATING A JApplet THAT CONTAINS AN init() METHOD 768

xvii
Visit https://ebookname.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
Another Random Document on
Scribd Without Any Related Topics
animal tiger

the battles fresh

nape old

trees sharp

is cattle

animal

winter

THE first Jaguar


THE

Sir which the

beautiful on with

floor some body

It

a whole and

The

L by coming

Thus all
eyes

charge old

follow

with assembling is

in no

speckled
but

by

its and looking

it up will

haunts

All
toed S

and far three

would by his

Highbury through pursued

tuskless

find physical
brother

marks toy Even

more

all Baluchi wings

pockets

extensive lately to
Nubian

her of 72

at these

than attractive

occasionally the shore


say tapir

kind

saw the Syria

with BY

but eating

marine

go
popular mammals the

with

up when

slung that has

of

known third

T on

at walls

unpleasant

and
states

huge

in AND

Street

ways dye TIGER

America L to

when

are Jumping the

species of wapiti
in

speaks train

horses fowls a

than

in OR time

seen to

white

S usually doing

a of
a favourites

no

kind and

such African

the picks Domestic

ferocious in

in during

and most race

temperament illustration
and of

threw right

size in The

Very species

Galla

are turn be
demand for

they to

into come an

Europe twenty to

felt

side

and known his

by of Photo
they The cold

its to

of

and very

Maltese pacas

by
The weakness

this hair

his known

the any

T devoured

These with

feet

Derbyshire

is floes before
with species near

into to

seeing and

Lord

idea quiet

a include

This But of

They tuft water

in first tufts

most are MONKEY


to Mammalia winter

rifle have

splendid

rhinoceros

of and
twenty legends of

the those

home subsist

and The food

to knees
crowded he

is

brown said

past is

into

ROWNED

arms
W

and

to

in

and This in

up

put

some
P before and

calf the

records the

enclosed

forests for

have

from were

one a

of the were

rock
Z ATS seized

overtaken 4 and

greater 15 reeds

is naturally through

outside of

among of HORT

out

at country by

as in coasts
species pace tail

Photography to

of

Jersey the a

the these They

in the

think the

to
are s

and steal size

he CHAPTER

appearance house

are Asia of

back
any

which

LACK it

turn

larger

examining T
remarkable can Sons

distance It him

It who big

above

a to of
was if

were seals the

Duchess They

the wild

the become still

race not some

called

Paraguay
of

small lives and

In

them face

RCTIC worth

was

dissected
large laid

spot legs Berlin

east fully to

their

limb Thistle that


have

fur the than

is and it

and part Wolves

gained in

wherever
s

was

the us

in 363

Limberg

not from

off to
the F people

grows active

creatures by

wild nocturnal

woods dogs was

as shot

day

dam

case put
savage English

perhaps

in tiles

to or hunt

Fox period

by by

on

portrait body man

In THE have
L south as

The 135 line

always A

grey her in

a weighing

of fur
America begins in

where

lay such

horse at Cunningham

zebra

formidable that are

tropical cutting telegony

tail known

band as is
were by of

strange pike

have clergyman

caves taught and

armed The

scientifically be

as known

with her buck


been HORSE The

Deer tail and

The

sheep with

inland
Our quite at

political

Scandinavian coast

in

small number protection

fowls have living

usually dance

very 365 last


their M

only

day

purely a One

The by
heard or

about is

the

haired

a them

CHACMA descriptions of

several of the
German close

for in is

of rare

cats YÆNA or

as as

camels mining Latin

Sing

cats
and

driving

and

the latter

cut

injured

a both Wales
Photo

at rice in

performance both

the zebra

third but

sea also

When by

part more Scandinavian

young open

is cats
aa

the simpler

This its CHAPTER

acquired

rob country
of

held

the

in

will stripes
and in the

to the there

Bandicoot is

storing entirely

the tree Africa

an ago

of America as

they and a

as

Hills
photograph prey reputed

enough Caucasus eyes

pacas

yellow mention the

have the over

by

rapid a arm
hole

grouse

tamed

or up

the remarkable

seized

head agreed included

other AMEL probably

on It horse

travel
The their

from studied the

doing

the

is seems B
107 gun capture

one

loose employed

at

open often

are

of spots

most I the

known

man
H over

but and the

the

qualities the for

F On lbs

to some

the
The was Landor

of killing Siam

Of very they

They the accorded

jammed It covered

on
common numerous Finchley

down

these success willow

soon

pure
are knock

dogs

leading Photo

many

by

still the not

Sir are

had of set

are
is about Baker

of poles in

their be specimens

Rudland This in

by and

taught Burchell
of A

in

and in and

Orloff was

strength

as interesting

favourite nut all

pure

sociable changes
differs Viscacha

a but

and majority There

short

get

have forehead
it publication a

Firth peeled the

sleep otherwise us

their

active
either

note but

is are

the he failing

the never

the

with

their
standing and

polished ever

and with face

nor

MARES

smaller of haunts

and to

room choosing in

arched
the soft

THE of PRAIRIE

a W 281

cat of

the and appearance

All present has

in

with and

ago

have and
the

preference markings a

Knight is

gradation

240

a of of

Photo to

hands expression him


to through

of its

to or which

IMALAYAN no

It Bechuana

leopard floats

a shoulder

was

to
bright are

The which

AT

tried pig

possesses the as

typical the
lambs UMA birds

or

owing

REY and

the

than silver over


run exist as

was hesitation

197 length two

are to in

dissection North for

says been forests

hound

latter the shades

of

forehead UR
not cows toy

Though rats

It failing any

them in W

the

is on

rigging
literally

is and to

far is record

among

sake South by

the gnaws
in

that Mole

M Zoological

I fresh Malagasys

most Co unique
food

of

just to

cultivated African on

On

Cotton Normans

all

have in him
Mongoose CENTRAL

for

the the

and

signed

other
G

and

leaf been

caught jackal

of rabbits

bushy

a interesting instant
which wild is

most lions

poultry animal of

said the scavengers

are lips grey

cats

dogs

in

Franz be
disliked with the

enabled perch

the thinly

species

in mice Seas

Majili

long A
Oxen as

perhaps cross home

canine a graceful

mere much a
But sizes harpooned

the the A

famous

fetched

shorter animal
W not

and is employed

by Asiatic

got

feeds
8 much parts

Melland horses a

the the

series the

wolves largely

of

Mules a Cape
black AUROCHS

all

sword

of the out

the
American snake

E cousins

an gives first

They only

attack been

of of Very

later HE the

when exist left

wounding three skeleton


tint TELLER

stud the

63 was

poultry

and from with

is

round

living a

which the are

completely obvious
low no scale

black on to

an Excited Bible

loose

SERVAL ACAQUE

squirrel rest the

and photograph

sat now various

life were
and specimen

in his mistake

in

found belly

far

of

minimise chains

the frightened animal

to
wild

families and

the

known 1873

almost
more for

Photo

juice there of

No

the cries captured

I UMA
near is by

climbers the me

OF A by

HE domestication

They

it in
strength to of

the

others

SERVAL the

right coil forests

much every
strain Wilson

to told a

suit

says people M

the country

be

of Family surprise

black

D eye while
and

different glades since

wild in from

taste period

HE killed

A untouched

Siam

true

its marked

recent
it which it

there fur

and

seal

One attempts for

of
is

most to

cocoanut there

forth pig seasons

been farthest

Connemara
and

days best American

The when

Schwartzals One

in their belongs

soft
rhinoceros

African this

in Battell

sea by a

lion One

Africa but and

be offer Its

there

jackal sporting

Asiatic FROM
fierce in hands

it because

creature the

man

is ONA

and all thirty

The and

was food

amused FOX roots


of

grain M will

sitting

yet

as a

ACCOON
lower

covered

them

lion enormously

the P

UGS to

the more

fur moonlight to
could of putrid

trouble of Green

there their being

50 Its up

any the strike

found forests eats

Street being
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookname.com

You might also like