intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Java Programming for absolute beginner- P27

Chia sẻ: Cong Thanh | Ngày: | Loại File: PDF | Số trang:20

55
lượt xem
5
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Java Programming for absolute beginner- P27:Hello and welcome to Java Programming for the Absolute Beginner. You probably already have a good understanding of how to use your computer. These days it’s hard to find someone who doesn’t, given the importance of computers in today’s world. Learning to control your computer intimately is what will separate you from the pack! By reading this book, you learn how to accomplish just that through the magic of programming.

Chủ đề:
Lưu

Nội dung Text: Java Programming for absolute beginner- P27

  1. JavaProgAbsBeg-50A.qxd 2/25/03 8:58 AM Page 478 478 Java Programming for the Absolute Beginner Java SDK Click on the Java SDK button to get to this page. From this page, you can run the installation file, which will install Java SDK, version 1.3.1. There are different files depending on which operating system you have. Look for the file that is right for your operating system. If you have any Windows version, look under the Microsoft section. If you are using Linux, look under the Linux x86 section. If you want to install the SDK on a Solaris machine, look under the Solaris SPARC/x86 section. You can find the instructions for installing and setting up the SDK for your system in Chapter 1, “Getting Started.” You can also find the Java Documentation installation here. You can either install the documentation on your system or browse it online on Sun’s Web site by using the URL http://java.sun.com/j2se/1.3/docs/. Source Code All of the source code of the examples in this book can be found on the CD-ROM. Click on the Source Code button to get to the source code page. The source code and class files are organized under their respective chapters. Each chapter gives you the option to either browse or download the files. If you chose to download, click the Download button. The download file is in ZIP format, so you will need an unzip tool, such as Winzip (included on the CD-ROM), to unpack the files into the local directory of your choosing. If you choose to browse the files without sav- ing them to your local disk, click Explore. A new window will open up that con- tains the files associated with that chapter. The file extension for the source code is .java. You can open this file with any text editor since it is a straight text file. It is still possible to run the example programs without installing them locally. To do this, you need to open up a shell (command prompt) and change to the class file directory. For example, if you’re using Windows and your CD-ROM drive letter is D, to run the HelloWorld example from Chapter 1, you need to change to the directory D:\Source Code\Chapter 1\. Next, you need to run the java com- mand on the program. (Note: you can only do this after you’ve installed the SDK.) For example, this is what you type at your command prompt to run the Hel- loWorld application: java HelloWorld. TEAM LinG - Live, Informative, Non-cost and Genuine! Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  2. JavaProgAbsBeg-50A.qxd 2/25/03 8:58 AM Page 479 479 Web Links Appendix A The Web Links section includes links to some useful Internet sites. To get to this section, simply click the Web Links button. The links you will find there are: Sun Java This takes you directly to Sun’s Java Web site. (http://java.sun.com). Sun Microsystems This takes you to Sun’s main Web site. Sun Using the CD-ROM Microsystems is the innovator behind Java technology. (http://www.sun.com). Sun Educational Services Here you can learn how to further your Java education and become a Sun-certified Java programmer! (http://suned.sun.com). East Coast Games A site written by programmers that you can use as a resource for your video game pro- gramming endeavors. (http://www.east- coastgames.com). NetBeans NetBeans is an open source integrated devel- opment environment (IDE) that you can download and use to facilitate your Java appli- cation programming projects (http://www.net- beans.org). Programs This section includes some programs that you can install and use on your system. To get to this section, click on the Programs button. For installation instructions, visit the Web site link, which is under the program name listing on this page. The programs are: Cool Edit Pro This is a demo version of a very cool audio editing program. The GIMP The GIMP is a powerful image-editing tool. Just install it and thank me later. It rocks. Internet Explorer 5.5 Microsoft’s very popular Internet browser. You can install this latest version and run the applet examples from the book with it. Winzip 8.0 Winzip is a great tool for packaging and unpacking file archives. TEAM LinG - Live, Informative, Non-cost and Genuine! Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  3. This page intentionally left blank TEAM LinG - Live, Informative, Non-cost and Genuine! Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  4. JavaProgAbsBeg-50B.qxd 2/25/03 8:59 AM Page 481 B A P P E N D I X Java Language Summary Reserved Words The following list included Java’s reserved words, also known as key- words. You cannot use them to name identifiers. abstract default if private this boolean do implements protected throw break double import public throws byte else instanceof return transient case extends int short try catch final interface static void char finally long strictfp volatile class float native super while const for new switch continue goto package synchronized The boolean literals true and false, and the null literal, although not technically keywords, cannot be used as identifiers either. TEAM LinG - Live, Informative, Non-cost and Genuine! Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  5. JavaProgAbsBeg-50B.qxd 2/25/03 8:59 AM Page 482 482 Java Programming for the Absolute Beginner Primitive Data Types Type Number of Bits boolean 1 byte 8 short 16 char 16 int 32 float 32 long 64 double 64 Ranges for Integral Types Type Minimum Maximum byte -27 27 – 1 short -215 215 – 1 int -231 231 – 1 long -263 263 – 1 char 0 216 – 1 Floating-Point Constants Float.NEGATIVE_INFINITY Float.POSITIVE_INFINITY Float.NaN Double.NEGATIVE_INFINITY Double.POSITIVE_INFINITY Double.NaN NaN stands for “not a number” and represents values of undefined operations such as 0.0 / 0.0. TEAM LinG - Live, Informative, Non-cost and Genuine! Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  6. JavaProgAbsBeg-50B.qxd 2/25/03 8:59 AM Page 483 483 Comments Appendix B There are three types of comments used in Java (single line, multi-line, and javadoc). This is a single line comment example: // this is a single line comment This is a multi-line comment example: Java Language Summary /* this is a multi-line comment */ This is a javadoc comment example: /** * This is a javadoc comment */ Literals Literals are used in Java to represent values that are of the primitive, String, or null types in source code. The following sections summarize their syntaxes. Any- thing within square braces ([ and ]) is optional and the bar character (|) sepa- rates different options. For example, [+|-] means the code can include +, -, or neither (because they are within square brackets). Integer Literals Integer literals can be expressed in octal (base 8), decimal (base 10), or hexadeci- mal (base 16). Octal digits can be any digits from 0 to 7. Decimal digits can be any digits ranging from 0 to 9. Hexadecimal digits can be any digit ranging from 0 to 9 and also any letter (case-insensitive) from A to F. A=10, B=11, C=12, D=13, E=14, F=15. The syntax for an integer literal is: [+|-][0[X|x]]number[L|l] Example Description 67 int literal having value 67 +67 int literal having value 67 -67 negative int literal having value –67 012 octal int literal having value 10 TEAM LinG - Live, Informative, Non-cost and Genuine! Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  7. JavaProgAbsBeg-50B.qxd 2/25/03 8:59 AM Page 484 484 -0X27C hexadecimal int literal having value –636 1234567890L long literal having value 1,234,567,890 Java Programming for the Absolute Beginner -0XBEL hexadecimal long literal having value -190 Floating-Point Literals A floating-point literal can be either a float or a double. The syntax for a float- ing-point number is: [+|-]number.number[[+|-]Eexponent|[+|-]eexponent][F|D|f|d] Example Description -10. double literal having value -10.0 +.01 double literal having value 0.01 1.23 double literal having value 1.23 1.23d double literal having value 1.23 1.23f float literal having value 1.23 2E4 double literal having value 20,000.0 (2x104) -133e-2F float literal having value -1.33 (-133x10-2) Boolean Literals Boolean literals must be either true or false. Character Literals A character literal is a single character or escape sequence enclosed in single quotes. The data type of a character literal is always char. A Unicode character escape sequence is in the form \unnnn, where nnnn is the hexadecimal represen- tation of the character. The syntax for a character literal is (exactly one character or escape sequence must appear within the single quotes): 'character|escape_sequence' Example Description 'a' char literal a '$' char literal $ '\u003F' char literal ? '\'' char literal ' (single quote) '\"' char literal " (double quote) TEAM LinG - Live, Informative, Non-cost and Genuine! Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  8. JavaProgAbsBeg-50B.qxd 2/25/03 8:59 AM Page 485 485 '\b' char literal for backspace '\f' char literal for form-feed Appendix B '\n' char literal for new line '\r' char literal for carriage return '\t' char literal for tab '\\' char literal for backslash (\) Java Language Summary String Literals A string literal consists of a string of characters and/or escape sequences within double quotes. The data type is always String. The syntax for a String literal is: "[characters&|escape_sequences]" Example Description "" The empty string "Abc" String literal Abc "\"Java\"" String literal "Java" "C:\\My Documents\\myfile.txt" String literal C:\My Documents\myfile.txt Null Literal The null literal is null. Operators In the following table, arg refers to any variable or value. Some operators only take certain types of arguments. For example, ! only works on Boolean types. Type Syntax Description Unary +arg, -arg Sign (positive or negative) ++variable Prefix increment variable++ Postfix increment --variable Prefix decrement variable-- Postfix decrement !arg Boolean compliment (Not) ~arg Bitwise inversion (type)arg Cast TEAM LinG - Live, Informative, Non-cost and Genuine! Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  9. JavaProgAbsBeg-50B.qxd 2/25/03 8:59 AM Page 486 486 Arithmetic arg + arg Addition arg - arg Subtraction Java Programming for the Absolute Beginner arg * arg Multiplication arg / arg Division arg % arg Modulus Shift arg >> arg Left shift arg >> arg Right shift arg >>> arg Unsigned right shift Comparison arg < arg Less than arg > arg Greater than arg = arg Greater than or equal to arg == arg Equal to arg != arg Not equal to arg instanceof Instance of class Bitwise arg & arg Bitwise AND arg | arg Bitwise OR arg ^ arg Bitwise XOR Logical arg && arg Logical AND arg || arg Logical OR Ternary condition ? val_if_true : val_if_false Conditional operator Assignment Operators Assignment operators store a value into a variable. This section covers the opera- tors that included the equals sign (=), however, the increment (++) and decrement (--) operators perform assignments as well. The assignment operator can be just the equals sign or the equals sign followed by an additional operator (although the combination of the two constitutes one single operator). The syntax for the assignment operator is: variable =[op] arg TEAM LinG - Live, Informative, Non-cost and Genuine! Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  10. JavaProgAbsBeg-50B.qxd 2/25/03 8:59 AM Page 487 487 If = is combined with another operator, the operation is logically equivalent to: Appendix B variable = variable op arg The following are all assignment operators: = += -= *= /= &= |= ^= %= = >>>= Java Language Summary Loops Name Syntax for loop for([init, init, …];[condition];[update, update, …]) { body } while loop while(condition) { body } do loop do { body } while (condition); Break and Continue The break and continue statements redirect the flow of loops. break takes con- trol out of the loop and continue returns control to the top of the loop. Conditionals The conditional statements are if, switch, and also the Ternary operator described in the “Operators” section. The syntax for the if conditional is (the square brackets [] indicate that the else if and else statements are optional and are not part of the syntax): if (condition) { statements_condition_true; } [else if (other_condition) { statements_other_condition_true; }, …] [else { statements_no_condition_true; }] TEAM LinG - Live, Informative, Non-cost and Genuine! Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  11. JavaProgAbsBeg-50B.qxd 2/25/03 8:59 AM Page 488 488 The syntax for the switch conditional is: Java Programming for the Absolute Beginner switch (test) { case value: [statements_test_equals_value] [break;] … [default: [statements_test_equals_no_case_value] } Try… Catch Blocks Try… catch blocks are used for exception handling. Here is the syntax: try { statements_that_might_cause_an_exception; } catch (exception_type exception_variable_name) { [statements_that_execute_if_exception_is_caught] } Class Definition The syntax for defining a class follows: [package package_name;] [[import Imported_class_or_package;] …] [access_modifier] class class_name [extends super_class_name] [implements implemented_Interface, …] { [class_definition] } Class Modifiers Modifier Description public Access modifier final Class cannot be subclassed abstract Must be subclassed (cannot be instantiated) Constructor Definition The syntax for a constructor is as follows. The first line of the constructor body must be either an explicit call to the superclass’s constructor using super(), an TEAM LinG - Live, Informative, Non-cost and Genuine! Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  12. JavaProgAbsBeg-50B.qxd 2/25/03 8:59 AM Page 489 489 implied call to the superclass’s no-arg constructor, or a call to another construc- tor within this class using this(): Appendix B [access_modifier] class_name([arg, …]) { [constructor_body] } Variable Declaration The syntax for declaring a variable is as follows: Java Language Summary [access_modifier] [modifier, ...] type variable_name [ = initial_value]; Variable Modifiers Modifier(s) Description public protected private Access modifiers static Indicates this is a class variable final Indicates a constant transient Indicates a variable that cannot be serialized volatile Indicates that variable may be modified asynchronously Method Definition The syntax for defining a method is as follows. Unless the return type is void, the last executable statement of any logical path of execution within the method must be a return statement that returns a value of type return_type: [access_modifier] [modifier, …] return_type method_name([arg, …]) [throws exception, …] { [body] } Method Modifiers Modifier(s) Definition public protected private Access modifiers static Indicates this is a class method final Indicates that this method cannot be over- ridden abstract Indicates the body must be defined in a subclass TEAM LinG - Live, Informative, Non-cost and Genuine! Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  13. JavaProgAbsBeg-50B.qxd 2/25/03 8:59 AM Page 490 490 native Indicates the method body is defined out- side of Java in a native library Java Programming for the Absolute Beginner synchronized Indicates that, at most, only one thread can have control of this method at any given time TEAM LinG - Live, Informative, Non-cost and Genuine! Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  14. JavaProgAbsBeg-90Index.qxd 2/25/03 8:59 AM Page 491 Index // (double slashes), 18 destroy() method, 290–292 / (division operator), 37 functions of, 20 - (subtraction operator), 37 HelloWeb applet example program, + (addition), 37 280–281 $ (dollar sign), 31 HTML document, incorporating in, % (modulus operator/division remainder), 21–22 37 images and, 304–306 * (multiplication operator), 37 init() method, 290–292 _ (underscore), 31 methods, list of, 281 3D rectangles, drawing, 319–320 QuizShow applet example, 306–310 running, 21–22 A sound files, 302–304 start() method, 290–292 abstract classes, 435–436 status messages, printing, 293 Abstract Windowing Toolkit. See AWT stop() method, 290–292 access modifiers, 143–145 in Web pages, 282–284 ActionEvents class, 247–249 applet HTML tag, 284–285 action commands, 252–255 passing parameters to applets, knowing source of, 248–252 284–288 methods, list of, 248–249 security restrictions, 290–291 addition (+), 37 using frames with, 288–290 AdjustmentEvents class, 258–260 writing Java programs as, 294 animations rewriting MadInputPanel example, double buffering, 367–369 295–298 ShootingRange game example, 370–376 rewriting MadLib game example, Sprite class 298–301 overview, 363–364 appleviewer utility, 20–22 testing, 365–367 applications applets applications versus applets, 279 Applet class, 282–284 examples of. See example code applets versus applications, 279 playing sound from, 369–370 creating, 20–21 arcs, drawing, 321–324 defined, 20, 279 arguments, command-line arguments, 46–47 TEAM LinG - Live, Informative, Non-cost and Genuine! Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  15. JavaProgAbsBeg-90Index.qxd 2/25/03 8:59 AM Page 492 492 arrays hitPlayer() method, 168 ArrayTest program example, 88–89 isPictureCard() method, 167 Index declaring, 85–86 play() method, 167–168 defined, 85 playerBlackJack() method, 168 elements, assigning values to, 85–88 private hit() method, 168 looping on, 104–106 RandomCardDeck class, 158–160 multidimensional, 87–89 reset() method, 152 subscripts, 85–86 shuffle() method, 158–160 assigning values to variables, 31–34 SimpleCardDeck class example, 123–127 AWT (Abstract Windowing Toolkit), 172–173 source code, example of, 162–167 components updatePoints() method, 168 buttons, 184–187 Vector class, 160–163 canvas, 202–203 Block Game checkbox, 198–202 block area, 378–380 choice, 192–195 block shape, 378–380 dialog, 211–214 BlockGame.java, source code listing, labels, 182–185 423–427 list, 195–198 BlockGrid class, creating listof, 173–176 addBlock() method, 385–386 menu, 203–207 block area, 384–386 panel, 208–209 blockOutOfBounds() method, 387–388 pop-up menu, 206–208 collision detection, 388–389 scrollbar, 209–213 methods, list of, 386–387 text area, 190–193 removeBlock() method, 385–386 textfield, 186–191 setBlock() method, 385–386 events, 177 source code listing, 389–392 Frame component, 178–180 Block.java application, source code graphics, 177–178 listing, 381–384 package classes, 172–173 blockOutOfArea() method, 388–389 BlockTest.java application, source code listing, 384 B concept of, 378 blackjack card game controls, 378 addUpPoints() method, 168 createBlock() method, 423–424 Card class, writing, 147–151 introduceNextBlock() method, 423–424 CardDeck class, 150–153 PlayArea class deal() method, 152 block movements, 401–403 dealerBlackJack() method, 168 EventThread inner class, 407–409 deck’s list() method, 126–127 falling blocks, 404–407 explanation of, 122–123 inner classes, 398–401 hitDealer() method, 168 TEAM LinG - Live, Informative, Non-cost and Genuine! Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  16. JavaProgAbsBeg-90Index.qxd 2/25/03 8:59 AM Page 493 493 PlayArea.java, source code listing, source code examples, 778 409–414 Web links, 479 Index PlayAreaTest.java, source code listing, character escape codes, 29–31 414–415 Checkbox component (AWT), 198–202 PlayArea Event model, 394 Choice component (AWT), 176, 192–195 building from scratch, 395–396 class variables, 126–127 PlayAreaEvent class, 397 classes PlayAreaEvents, firing, 398–399 abstract, 435–436 PlayAreaListener interface, 397–398 BufferedReader, 40–42 PlayAreaListeners, registering, 398 extending, 22, 154–157 rotateClockwise() method, 380–381 importing, 22 rotateCountClockwise() method, 380, inner, 398–399 381–382 InputStreamReader, 40 ScoreInfoPanel class, 415–423 Math, 57 block statements, 16, 67–68 nested, 398–399 boolean isEnabled() method, 173–174 outer, 398–399 boolean isFocusTraversable() method, String, 48 173–174 subclasses, 22 boolean isLightWeight() method, 173–174 super classes, 22 boolean logical operators, 70–72 Vector, 160–163 BorderLayout layout manager, 227–229 CodeBase() method, 302–303 break statement, loops and, 112–116 collision detection, Block Game example, brighter() method, Color class, 337–338 388–389 BufferedReader class, 40–42 Color class Button class, 184–187 brighter() method, 337–338 buttons (AWT), 176 color values, 340–344 byte code, 5 ColorCanvas application, 340–341 bytes, converting strings to, 45 ColorChanger application, 340–342 ColorSliders application, 343 C ColorTest application, source code, calculations, percentages, 34–35 337–339 Canvas component (AWT), 176, 202–203 darker() method, 337–338 CardLayout layout manager, 238–242 methods, list of, 337–338 casting data types, 28–29 setColor() method, 136 catch clause, exception handling and, 43 command-line arguments, 46–47 cd command, 12–13 command-line input, 38–39 CD-ROM commands. See also methods Java SDK, 478 cd, 12–13 programs, list of, 479 javac, 21 TEAM LinG - Live, Informative, Non-cost and Genuine! Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  17. JavaProgAbsBeg-90Index.qxd 2/25/03 8:59 AM Page 494 494 comments documentation comment, 435–438 adding to code, 17–19 dollar sign ($), 31 Index documentation comment, 435–438 double buffering, 367–369 ending, 18 double slashes (//), 18 free text, 19 drawing javadoc, 435–438 arcs, 321–324 multi-line, 18 images single-line, 18 drawImage() method, 332–333 starting, 18 getHeight() method, 334–335 components getImage() method, 333–334 AWT, list of, 175–176 getWidth() method, 334–335 class methods, list of, 173–176 ImageTest application, source code, heavyweight, 431 333–334 lightweight, 431–433 ImageTest2 application, source code, compound increment assignment operator, 334–336 99–100 size command-line arguments, 336 concatenation, 48–49 lines, 315–316 conditional operators, 68–69 ovals, 321–322 conditional statements, 66–67 polygons, 323–326 constant fields, declaring, 129 rectangles, 317–320 constructor methods, 140–142 strings, 325–327 createStory() method, 272–273 drive() method, 435–436 D E darker() method, Color class, 337–338 encapsulation, 146–148 data types endless loop, 112 casting, 28–29 escape codes, 29–31 defined, 26 event handling primitive, 27 ActionEvents, 247–249 declaring action commands, 252–255 arrays, 85–86 knowing source of, 248–252 constant fields, 129 methods, list of, 248–249 methods, 136–137 AdjustmentEvents, 258–260 packages, 434–435 FocusEvents, 254–256 variables, 31–32 ItemEvents, 255–259 destroy() method, 281, 290–292 KeyEvents, 265–268 Dialog component (AWT), 211–214 MouseEvents, 261–265 dispose() method, 181, 244 overview, 241–242 division operator (/), 37 TextEvents, 260–262 do loop, 109–111 WindowEvents, 242–245 TEAM LinG - Live, Informative, Non-cost and Genuine! Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  18. JavaProgAbsBeg-90Index.qxd 2/25/03 8:59 AM Page 495 495 events, event listener interfaces, 177 MouseTest application, source code, example codes 262–264 Index AdjustmentTest application, source code, NameGame example, 26 258–260 source code, 49–52 ArcTest application, source code, NumberGuesser application, 94 322–323 source code, 118–120 ArrayTest program, 88–89 operator precedence, 37 blackjack card game. See blackjack card OvalTest application, source code, game 321–322 Block Game. See Block Game PolyTest application, source code, BorderLayout layout manager, source 323–325 code, 228–229 QuizShowApplet, source code, 306–310 CardLayoutTest application, 238–242 Racer program, 95–96 CountByFive program, 99 RectText application, source code, CountDown program, 101–103 318–319 DiceRoller application, 65–67 ShootingRange game, source code, encapsulation, 146–148 370–376 FlowLayout layout manager, source code, SoundApplication, source code, 369–370 223–225 StringTest application, source code, FocusTest application, source code, 325–326 254–255 TextTest application, source code, FortuneTeller program, 90–911 261–262 FrameTestApplet application, source TipAdder program, 34–36 code, 289 TipCalculator program, 45–46 HelloWeb applet program, 280–281 user input, 38–39 ImageTest application, source code, exception handling 333–334 catch clause, 43 ImageTest2 application, source code, IOException, 43 334–336 loops and, 115–117 ItemTest application, source code, overview, 41–42 255–258 try-catch block, 116–117 KeyTest application, source code, extending classes, 22, 154–157 267–268 extends() keyword, 154 LineTest application, source code, 315–316 LowTemp program, 73–74 F MadLib game. See MadLib game field access modifiers, 144–145 ManyTemps program, 79–80 field modifiers, 130–132 Math game, 43 final keyword, 129 Mine Cell. See Mine Cell floating-point numbers, 34–35 FlowLayout layout manager, 223–226 TEAM LinG - Live, Informative, Non-cost and Genuine! Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  19. JavaProgAbsBeg-90Index.qxd 2/25/03 8:59 AM Page 496 496 FocusEvents, 254–256 getX() method, 173–174 fonts getY() method, 173–174 Index Font class, 326–328 Graphics class Font constructor method, 326–327 Color class FontMetrics class, 331–333 ColorTest application, source code, getFontMetrics() method, 327–328 337–339 methods, list of, 328–329 methods, list of, 337 source code, 328–331 drawing setFont() method, 326–327 arcs, 321–324 for loop, 96 lines, 315–316 counting backwards, 101–103 ovals, 321–322 nested, 102–105 polygons, 323–326 overview, 96 rectangles, 317–319 Frame component (AWT), 176 rectangles, 3D, 319–320 GUIFrame class, creating, 237–238 strings, 325–327 methods, list of, 177–178 Memory Game example, 343–344 using with applets, 288–290 Memory class, creating, 348–351 MemoryCell class, creating, 344–349 G overview, 314–315 paint(Graphics method), 314–315 getAppletInfo() method, 281, 285–286 GridBagLayout layout manager, 229–236 getBackground() method, 173–174 GridLayout layout manager, 225–228 getBound() method, 173–174 GUI Frame class, creating, 237–238 getFont() method, 173–174 getFontMetrics() method, 327–328 getForeground() method, 173–174 H getHeight() method, 173–174, 334–335 handling events getID() method, 455 ActionEvents, 247–249 getImage() method, 333–334 action commands, 252–255 getInteriorSize() method, 447–448 knowing source of, 248–252 getItem() method, 257–258 methods, list of, 248–249 getKeyCode() method, 267 AdjustmentEvents, 258–260 getParameter() method, 284–285 FocusEvents, 254–256 getParameterInfo() method, 285–286 ItemEvents, 255–259 getPreferredSize() method, 173–174 KeyEvents, 265–268 getSize() method, 173–174 MouseEvents, 261–265 getSource() method, 244, 465–466 overview, 241–242 getStateChange() method, 257–258 TextEvents, 260–262 getStringArray() method, 268–269 WindowEvents, 242–245 getUserInput() method, 167 handling exceptions. See exception getWidth() method, 173–174, 334–335 handling TEAM LinG - Live, Informative, Non-cost and Genuine! Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  20. JavaProgAbsBeg-90Index.qxd 2/25/03 8:59 AM Page 497 497 heavyweight components, 431 InputStreamReader class, 40 HTML document, incorporating into installing Java Software Development Kit Index applets, 21–22 Linux installation, 10–11 Solaris installation, 10 I Windows (Win32) installation, 8–10 if-else statement, 74, 75–76 instance variables, 126–127 flowchart, 74–75 integer bitwise operators, 71–72 indentation, 80–81 Integer.parseInt() method, 44–45 ManyTemps program example, 79–80 interrupt() method, 361–362 nested, 77–79 ItemEvents class, 255–259 syntax conventions, 80–81 if statement, random numbers and, 66–68 J images Java applets and, 304–306 byte code, 5 drawing history of, 28–29 drawImage() method, 332–333 Java Software Development Kit, getHeight() method, 334–335 installing getImage() method, 333–334 Linux installation, 10–11 getWidth() method, 334–335 Solaris installation, 10 ImageTest application, source code, Windows (Win32) installation, 8–10 333–334 overview, 3–4 ImageTest2 application, source code, platform independence, 4–5 334–336 procedure-oriented program, 5 size command-line arguments, 336 reasons for using, 7–8 import statement, 22 syntax, 15 importing classes, 22 Java run-time environment (JRE), 5 increment operators, 96–97 javac command, 21 assignment operator, 99 javadoc tags, 435–438 compound assignment, 99–100 JRE ( Java run-time environment), 5 postfix, 96–97 prefix, 97–98 K incremental values, 98–99 KeyEvents class, 265–268 index of strings, 48–49 keywords infinite loop, 112 extends, 154 inheritance, 154 final, 129 init() method, 280, 290–292 protected, 144–145 inner classes, 398–399 public, 16 input synchronized, 360–361 BufferedReader class, 40–42 this, 143 InputStreamReader class, 40 user input, example code, 38–39 TEAM LinG - Live, Informative, Non-cost and Genuine! Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2