Tải bản đầy đủ (.pdf) (6 trang)

Java Programming for absolute beginner- P28 docx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (88.31 KB, 6 trang )

L
Label class, 183–185
labels, 175
layout managers
BorderLayout, 227–229
CardLayout, 238–242
FlowLayout, 223–226
GridBagLayout, 229–236
GridLayout, 225–228
overview, 223
lightweight components, 431
creating, 432–433
jpr.lightweight package, creating
documentation for, 450–453
JPRButton3D class, 447–451
JPRButton3D class, testing, 451–454
JPRComponent3D class, source code,
437–443, 447–448
JPRRectComponent3D class, 444–447
lines, drawing, 315–316
Linux, installing SDK on, 10–11
List component (AWT), 176, 195–198
list() method, 124
literals
case sensitivity, 28–29
character escape codes, 29–31
defined, 28–29
local variables, 126–127
logical compliment operators, 69–70
loops
arrays, looping on, 104–106


break statement, 112–116
defined, 94–96
do, 109–111
endless, 112
exception handling, 115–117
infinite, 112
for loop, 96
counting backwards, 101–103
nested, 102–105
Racer program example code, 95–96
skipping values, 98–99
while, 108–110
M
MadLib game, 172–173
AdvancedMadLip application, creating,
271–275
game frame, creating, 217–219
MadDialog component, creating, 214–218
MadInputPanel class, creating, 268–272
main() method
command-line arguments and, 46–47
function of, 19
Math class, 57
methods, list of, 63
mathematical operations. See also
numbers, 37
counting backwards, 101–103
floating point math, list of, 37
integer math, list of, 37
modulus operators, 35–36

operator precedence, 37
percentages, 34–35
Math.random() method, 58
Menu component (AWT), 203–207
method access modifiers, 144–145
methods
block statements, 16
BoderLayout(), 228–229
boolean isEnabled(), 173–174
boolean isFocusTraversable(), 173–174
boolean isLightWeigth(), 173–174
brighter(), 337–338
buttons, list of, 184–187
CodeBase(), 302–303
constructor, 140–142
createStory(), 272–273
darker(), 337–338
declaring, 136–137
498
I
n
d
e
x
JavaProgAbsBeg-90Index.qxd 2/25/03 8:59 AM Page 498
TEAM LinG - Live, Informative, Non-cost and Genuine!
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
defined, 16
defining, 132–136
destroy(), 290–292

dispose(), 181–182, 244
drawImage(), 332–333
drive(), 435–436
getAppletInfo(), 281, 285–286
getBackgound(), 173–174
getBounds(), 173–174
getFont(), 173–174
getFontMetrics(), 327–328
getHeight(), 173–174, 334–335
getID(), 455
getImage(), 333–334
getInteriorSize(), 447–448
getItem(), 257–258
getKeyCode(), 267
getParameter(), 284–285
getParameterInfo(), 285–286
getPreferredSize(), 173–174
getSize(), 173–174
getSource(), 244, 465–466
getStateChange(), 257–258
getStringArray(), 268–269
getUserInput(), 167
getWidth(), 173–174, 334–335
getX(), 173–174
getY(), 173–174
GridLayout(), 227–228
init(), 280, 290–292
Integer.parseInt(), 44–45
interrupt(), 361–362
list(), 124

main()
command-line arguments and, 46–47
function of, 19
Math Class, 63
Math.random(), 58
method overloading, 138–140
method signature, 136
next(), 268–269
notify(), 361–362
notifyAll(), 361–362
overriding, 157–158
paint(), 23
passing parameters, 136–139
play(), 167, 370
previous(), 268–269
randomize(), 348–349
readParams(), 309
repaint(), 344–345
reset(), 152, 158–159
revealAll(), 468–469
rotateClockwise(), 380
rotateCounterClockwise(), 380
run(), 356, 358
setColor(), 136
setFont(), 326–327
setSeed(), 61
shuffle(), 158–159
start(), 290–292, 356
static methods, 140–141
stop(), 290–292

toString(), 157–158
update(), 363–364
values, returning, 139–140
wait(), 361–362
Mine Cell
MineCell class
importing, 456–457
MineCell.java, source code listing,
458–462
MouseEvent pass, 457–458
testing, 462–463
MineCellEvent class, 455–456
MineCellListener interface, 456
MineField class
checkIfSolved() method, 469
getSource() method, 465–466
members, declaring, 465–466
499
I
n
d
e
x
JavaProgAbsBeg-90Index.qxd 2/25/03 8:59 AM Page 499
TEAM LinG - Live, Informative, Non-cost and Genuine!
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
MineCell.EMPTY, source code,
467–468
MineField. java, source code listing,
470–474

randomizeField() method, 466–467
revealAll() method, 468–469
MineFieldEvent class, 464–465
MineFieldListener interface, 464–465
MinePatrol application, source code
listing, 474–476
modifiers, access modifiers, 144–145
modulus operators, 35–37
MouseEvents class, 261–265
multi-line comments, 18
multidimensional arrays, 87–89
multiplication operator (*), 37
N
naming variables, 31–32
nested classes, 398–399
nested if-else statements, 77–79
nested loops, 102–105
next() method, 268–269
notify() method, 361–362
notifyAll() method, 361–362
numbers. See also mathematical operations
floating-point, 34–35
operator precedence, 37
parsing strings to, 44–45
random numbers
AmIRandom program, 59–60
DiceRoller application example,
65–67
double, assigning, 57–58
even numbers only, 66–68

if statement, 66–68
MakerUtil application example, 58–59
Math Class method, list of, 63
MathClassTest application example,
62–64
Math.random() method, 58
methods, list of, 58
NumberMaker application sample, 57
pseudorandom numbers, 59–60
setSeed() method, 61
values, getting larger than 1, 65
values, skipping, 98–99
numerical comparison operators, 68–69
O
object-oriented programming (OOP)
encapsulation, 146–148
inheritance, 154
polymorphism, 157–158
OOP. See object-oriented programming
operators
boolean logical, 70–72
conditional, 68–69
increment, 96–97
compound assignment, 99–100
postfix, 96–97
prefix, 96–97
integer bitwise, 71–72
logical compliment, 69–70
numerical comparison, 68–69
operator precedence, 37

ternary, 72–73
outer classes, 398–399
ovals, drawing, 321–322
overriding methods, 157–158
P
packages
declaring, 434–435
defined, 40
paint() method, 23
Panel component (AWT), 208–209
parameters, passing parameters, 136–139
parsing strings to numbers, 44–45
500
I
n
d
e
x
JavaProgAbsBeg-90Index.qxd 2/25/03 8:59 AM Page 500
TEAM LinG - Live, Informative, Non-cost and Genuine!
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
passing parameters, 136–139
pausing threads, 361–362
percentages, calculating, 34–35
platform independence, 4–5
play() method, 167, 370
polygons, drawing, 323–326
polymorphism, 157–158
PopupMenu component (AWT), 206–208
postfix increment operators, 96–97

prefix increment operators, 96–97
previous() method, 268–269
Prima Tech Web site, 477
primitive data types, 27
printing status messages, 293
private variables, 144–145
procedure-oriented program, 5
programming languages, 4
programs
defined, 4
examples of. See example codes
procedure-oriented, 5
protected keyword, 144–145
pseudorandom numbers, 59–60
public keyword, 16
R
random numbers
AmIRandom program, 59–60
DiceRoller application example, 65–67
double, assigning, 57–58
even numbers only, 66–68
if statement, 66–68
Math Class method, list of, 63
MathClassTest application example, 64
Math.random() method, 58
NumberMaker application source code
sample, 57
pseudorandom numbers, 59–60
Random class
MakerUtil application, source code

example, 58–59
methods, list of, 58
setSeed() method, 61
values, getting larger than 1, 65
randomize() method, 348–349
readParams() method, 309
rectangles, drawing, 317–320
repaint() method, 344–345
reset() method, 152, 158–159
returning values, 139–140
revealAll() method, 468–469
rotateClockwise() method, 380
rotateCounterClockwise() method, 380
run() method, 356, 358
S
sample codes. See also example codes
Hello, World application sample
compiling, 12–14
running, 14–15
source code, 12–13
HelloWeb applet, 2–3
NumberMaker application, source code,
57
Scrollbar component (AWT), 176, 209–213
security
applets, 290–291
thread-safe code, 360–361
sentinel values, 101
setColor() method, 136
setFont() method, 326–327

setSeed() method, 61
shuffle() method, 158–159
single-line comments, 18
skipping values, 98–99
Solaris, installing SDK on, 10
501
I
n
d
e
x
JavaProgAbsBeg-90Index.qxd 2/25/03 8:59 AM Page 501
TEAM LinG - Live, Informative, Non-cost and Genuine!
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
sound files
applets and, 302–304
playing from applications, 369–370
SoundApplication, source code, 369–370
source code. See example codes
Sprite class
overview, 363–364
testing, 365–367
start() method, 290–292, 356
statements
block statements, 16, 67–68
break statement, loops and, 112–116
conditional statements, 66–67
if-else, 74, 75–76
flowchart, 74–75
indentation, 80–81

ManyTemps program example, 79–80
syntax convention, 80–81
import, 22
switch, 80–82
case values, 82
compile-time errors, 82
FuzzyDice program example, 83–84
static methods, 140–141
static variables, 127–129
status messages, printing, 293
stop() method, 290–292
strings
concatenation, 48–49
defined, 48
drawing, 325–327
index of, 48–49
methods, list of, 49–50
parsing to numbers, 44–45
String class, 48
String objects, 48–49
substrings, 48
subclasses, 22
subtraction operator (-), 37
super classes, 22
switch statement, 80–82
case values, 82
compile-time errors, 82
FuzzyDice program example, 83–84
synchronized keyword, 360–361
syntax, 15

T
tags, javadoc, 436–437
ternary operators, 72–73
TextArea component (AWT), 176, 190–191,
192–193
TextEvents class, 260–262
TextField (AWT), 176
TextField class, 186–191
this keyword, 143
threads
creating
using Runnable interface, 358–359
using Thread class, 356–357
defined, 354
interrupt() method, 361–362
multithreading, problems associated
with, 358–361
notify() method, 361–362
notifyall() method, 361–362
output, order of, 355
pausing, 361–362
thread-safe code, 360–361
wait() method, 361–362
toString() method, 157–158
try-catch block, exception handling and,
116–117
U
underscore (_), 31
Unicode, 27
update() method, 363–364

502
I
n
d
e
x
JavaProgAbsBeg-90Index.qxd 2/25/03 8:59 AM Page 502
TEAM LinG - Live, Informative, Non-cost and Genuine!
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
user input
BufferedReader class, 40–42
example code, 38–39
InputStreamReader class, 40
V
values
assigning
to arrays, 85–88
to variables, 31–34
returning, 139–140
sentinel, 101
variables
assigning values to, 31–34
class, 126–127
declaring, 31–32
defined, 26–27
instance, 126–127
local, 126–127
naming, 31–32
private, 144–145
static, 127–129

Vector class, 160–163
W
wait() method, 361–362
Web pages, including applets in, 282–284
applet HTML tag, 284–285
passing parameters to applets, 284–288
security restrictions, 290–291
using frames with, 288–290
while loop, 108–110
WindowListener interface, 242–245
Windows Update Web site, 279
Windows (Win32) installation, installing
SDK on, 8–10
503
I
n
d
e
x
JavaProgAbsBeg-90Index.qxd 2/25/03 8:59 AM Page 503
TEAM LinG - Live, Informative, Non-cost and Genuine!
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.

×