O'Reilly logo

Learning Java Through Games by Lubomir Stanchev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

List of Figures
0.1 Chaptersequence. ................................ xiv
1.1 A Colossus Mark 2 computer. Artwork created by United Kingdom Govern-
ment. ....................................... 4
1.2 An Intel 80486DX2 CPU from above. Photographed by Andrew Dunn. The
picture is licensed under the Creative Commons Attribution-Share Alike 2.0
Genericlicense................................... 4
1.3 DDRAM memory modules for desktop computers. Picture is from Wikipedia
commons. ..................................... 5
1.4 The game Tennis for Two. The screen shot is taken from a video made by
the Brookhaven National Laboratory, a United States Government laboratory. 8
1.5 ThegameSpacewar. ............................... 9
1.6 ThegamePong. ................................. 9
2.1 Creating a new Java project. .......................... 12
2.2 Setting the properties of a Java Application project. ............. 13
2.3 CreatinganewJavaclass............................. 13
2.4 Exampleprogramexecution. .......................... 16
2.5 Allocatingintegerinmainmemory........................ 19
2.6 The if-else construct. ............................. 25
2.7 The if construct.................................. 26
2.8 ASCIIcodetable.................................. 31
2.9 The switch statement............................... 33
3.1 The while construct................................ 42
3.2 The do-while construct.............................. 44
3.3 The for statement................................. 46
4.1 Thedierentpartsofamethod. ........................ 62
4.2 Passing parameters between methods. . .................... 70
5.1 Examplearray. .................................. 85
5.2 Passinganarraytoamethod........................... 92
5.3 Exampleofshallowcopy. ............................ 94
5.4 ExampleBattleshipboard. ........................... 99
5.5 Initialarray..................................... 100
5.6 Example of ragged array. ............................ 101
6.1 Interfaceofaclass................................. 111
6.2 Example of object. ................................ 114
6.3 The Die class.................................... 118
7.1 Passinganimmutableobjecttoamethod.................... 139
xvii
xviii List of Figures
7.2 Passingamutableobjecttoamethod...................... 140
7.3 Headsofdierentcoins. ............................. 144
8.1 Objectcomposition. ............................... 160
8.2 Classinheritanceexample............................. 162
8.3 Class inheritance and super object. . . . .................... 163
8.4 Exampleofmultipleinheritance. ........................ 164
8.5 Autocasting. ................................... 170
8.6 Inheritancehierarchy. .............................. 174
8.7 Cloningexample.................................. 182
9.1 TheBreakoutgame. ............................... 195
9.2 Pixelsinascreen. ................................ 197
9.3 Coordinatesofaball. .............................. 202
9.4 PictureforExercise1. .............................. 211
9.5 PictureforExercise2. .............................. 212
10.1Exampleofinnerclass............................... 217
10.2Exampleofkeylistener. ............................. 222
10.3Exampleofmulticasting.............................. 233
10.4StartoftheReversigame............................. 238
11.1UMLDiagramofthegameBreakout. ..................... 240
11.2 Explanation of the below method. ....................... 259
11.3 Pieces of the Tetris game. ............................ 265
12.1Theborderlayout. ................................ 270
12.2Degreeconverterprogram............................. 271
12.3Calculatorprogram. ............................... 273
12.4Afontcombobox. ................................ 277
12.5Exampleofacheckbox.............................. 279
12.6Exampleofradiobuttons............................. 282
12.7Exampleofadialogbox.............................. 284
12.8Exampleofapasswordeld. .......................... 286
13.1Thelechooserdialogbox. ........................... 300
13.2Movingthelecursor............................... 302
14.1ExampleofcomputingthefthFibonaccinumberrecursively......... 321
14.2 Example of computing the 5th Fibonacci number using dynamic programming. 322
14.3TowersofHanoi.PicturetakenfromWikipediaCommons........... 323
14.4Exampleofastack................................. 324
14.5Exampleofcomputing2!recursively....................... 325
15.1 Java Applet architecture. ............................ 344
15.2TheTic-Tac-Toeappletinsideawebbrowser.................. 347
15.3TheindexofthesquaresintheTic-Tac-Toegame. .............. 350

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required