Java 7 for Absolute Beginners

(nextflipdebug5) #1
CHAPTER 12 ■ VIDEO GAMES

Figure 12-1. The TargetClick game


Wondering why the spots are different sizes? We'll see why that happens as we study the
game's code.


The TargetClick game consists of three classes:


  • TargetClick manages the user interface, the game logic, and the game loop

  • TargetClickPanel creates the playing field and manages the targets

  • Target draws the targets


As you can tell from that description, the TargetClick class contains most of the game's complexity.

Listing 12-1. The TargetClick class


package com.bryantcs.examples.videogames;


import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;


import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;

Free download pdf