Computer Bible Games with Java

Table of Contents

1. Introduction

Preview 1-1
Introducing Computer Bible Games With Java 1-2
Requirements for Computer Bible Games With Java 1-3
Downloading and Installing JCreator 1-4
Testing the Installation 1-7
Getting Help with a Java Program 1-13
Structure of a Java Program 1-14
Structure of a Java GUI Application 1-15
Swing Controls 1-17
Stopwatch – Creating a Java Project with JCreator 1-20
Stopwatch – Create a Frame 1-26
Saving Java Projects with JCreator 1-29
JCreator and Java Files 1-30
Create the User Interface 1-31
Stopwatch – Adding Controls 1-35
Adding Event Methods 1-41
Stopwatch – Writing Code 1-45
Chapter Review 1-53

2. Bible Safecracker Project
Review and Preview 2-1
Safecracker Project Preview 2-2
Frame Design – GridBagLayout Manager 2-10
Safecracker Frame Design 2-15
Code Design – Initializing Stopped State 2-36
Code Design – Stopped to Playing State 2-39
Code Design – Playing to Stopped State 2-42
Code Design – Generating Secret Combination 2-44
Code Design – Accepting Player Input 2-49
Code Design – Checking Player Input 2-54
Sounds in Java 2-59
Code Design – Adding Sounds 2-61
Safecracker Project Review 2-68
Safecracker Project Enhancements 2-69
Safecracker Project Java Code Listing 2-70

3. Bible Tic Tac Toe Project

Review and Preview 3-1
Tic Tac Toe Project Preview 3-2
Tic Tac Toe Frame Design 3-10
Code Design – Initializing Stopped State 3-33
Code Design – Stopped to Playing State 3-36
Code Design – Playing to Stopped State 3-39
Code Design – Marking Grid 3-41
Code Design – Checking for Win 3-45
Code Design – Number of Players Selection 3-52
Code Design – Random Computer Moves 3-53
Code Design – Smart Computer Moves 3-58
Code Design – Adding Sounds 3-62
Tic Tac Toe Project Review 3-68
Tic Tac Toe Project Enhancements 3-69
Tic Tac Toe Project Java Code Listing 3-70
Bible Tic Tac Toe Trivia Game Enhancement 3-84
Code Design – Enlarge Form, Add New Controls 3-85
Code Design – Add Questions and Answers 3-89
Code Design – Display Question 3-94
Code Design – Answer Question 3-101
Play the Game 3-104
Code Design – One Last Change 3-110
Bible Tic Tac Toe Game Project Review 3-114

4. Bible Match Game Project

Review and Preview 4-1
Match Game Project Preview 4-2
Match Game Frame Design 4-10
Photo Selection 4-40
Code Design – Initializing Stopped State 4-43
Code Design – Integer Shuffling 4-50
Code Design – Stopped to Playing to Stopped State 4-54
Code Design – Displaying Photos 4-60
Timer Object 4-67
Code Design – Adding Delays 4-70
Code Design – One Player, Solitaire Game 4-78
Code Design – Computer Moves 4-84
Code Design – Random Computer 4-91
Code Design – Smart Computer 4-96
Match Game Project Review 4-108
Match Game Project Improvements 4-109
Match Game Project Java Code Listing 4-110

5. Noah’s Ark Project

Preview 2-1
Noah’s Ark Project Preview 2-2
Noah’s Ark Frame Design 2-6
Code Design – Initial State (Instructions) 2-17
Code Design – Select Number of Turtles 2-20
Code Design – Initial to Stopped State 2-22
Code Design – Stop the Program 2-27
Code Design – Selecting Turtles 2-28
Code Design – Stopped to Moving State 2-32
Noah’s Ark Project Review 2-37
Noah’s Ark Project Java Code Listing 2-38
6. Elijah and the Ravens Project

Preview 4-1
Elijah and the Ravens Project Preview 4-2
Elijah and the Ravens Frame Design 4-5
Code Design – Initial State (Instructions) 4-18
Code Design – Position Elijah 4-23
Code Design – Position Raven and Bread 4-28
Code Design – Stop the Program 4-32
Code Design – Dropping Bread 4-33
Code Design – Moving Elijah 4-36
Code Design – Catching Bread 4-41
Code Design – Stop the Game 4-44
Elijah and the Ravens Project Review 4-48
Elijah and the Ravens Project Java Code Listing 4-49

7. Daniel and the Lions Project

Preview 5-1
Daniel and the Lions Project Preview 5-2
Daniel and the Lions Frame Design 5-10
Code Design – Initial State (Instructions) 5-40
Code Design – Select Difficulty 5-43
Code Design – Draw Grid 5-45
Code Design – Position Rocks 5-49
Code Design – Position Daniel and Lions 5-54
Code Design – Stop the Program 5-59
Code Design – Moving Daniel 5-60
Code Design – Moving Lions 5-67
Code Design – Shooting Prayers 5-75
Code Design – Stop the Game 5-84
Daniel and the Lions Project Review 5-85
Daniel and the Lions Project Java Code Listing 5-86
Appendix. Distributing a Java Project
Preview A-1
Executable jar Files A-2
Creating a jar File in JCreator A-3
Creating a jar File in Command Prompt A-10
Application Icons A-12
Using IconEdit A-14
Running a Project on Another Computer A-18
Program Installers A-22
Installing/Removing a Java Application A-29