Assignment 2: Jumping Button


Description

This assignment handles topics of events and GUI-elements. It's a little game. The task: create a window with 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.

The following method relocates a JFrame on the screen to a random position (Toolkit and Dimension are in package java.awt):

public void relocate(JFrame f){
/*If this function is called, it will relocate the window to a new random position on the screen */
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension windowSize = f.getSize();
int x = rand.nextInt(screenSize.width - windowSize.width);
int y = rand.nextInt(screenSize.height - windowSize.height);
f.setLocation(x,y);
}

BONUS (3 points): Surround the button with 8 other buttons (=>grid 3x3) which the user is not allowed to hit! Enjoy! Bonus points will be given for extensions to the game idea. Be creative!

The basic assignment is 10 points. Due date: Wednesday Feb 3, 10pm.