Assignment 2: Jumping Button


Description

This assignment handles topics of events and GUI-elements. It's a little game. The task: create a button that randomly relocates to a different position on the screen each time it is hit. The player has to hit the button 15 times, the score is the time needed. You will be provided a framework that implements the button, the JFrame, the relocation, yet not the event handling.

Your first task: add the necessary event handling (5 points) and the game-framework (counter, score etc.). Measure the time using java's System.currentTimeMillis() method (see API). Please re-label the button each time with the number of remaining hits.

Your second task: add some GUI programming: to make the game more mean, surround the button with 8 buttons (GridLayout 3x3) which the player is NOT allowed to hit. if the center button is sufficiently small, the game becomes really hard. If the user clicks one of the 8 bad buttons by accident, the following should happen:
first time: the center button becomes smaller, but the game continues.
second time: game over.

Here's the class JumpingButton, your starting point. If you create an instance of this class, a button in the center of the screen will appear. Clicking it results in nothing, since no event handling is built in. The class also has a method 'relocate()'. If you call that class, the button will be displayed at a random position on the screen.

Enjoy! Bonus points will be given for extensions to the game idea. Be creative!