The day after these are assigned we will cover solutions in class. After that, I will post the solutions online.


  1. Working With Events Recall the Angry Homer game, where a cross-hair follows the mouse during the game. Your assignment is to accomplish something similar.

    Specifically, you must do the following:
    1. Start with the Events/Listeners sample code, listed under the Core Java examples on the website.
    2. Your applet should draw a cross-hair wherever the mouse goes on the applet.
    3. To do this, review the notes about Events (specifically MouseMotion events), as well as documentation for drawing to the canvas.
    4. The canvas is a Graphics object, whose documentation is here. Which methods look like they might be usefull?
    Note that there is much in the Events/Listeners sample code that neeeds to be removed and/or altered for this to work properly!

    Mouse around the area below for a demonstration:
    Must install Java to see this applet.

  2. Working with Events Part 2 For this assignment, you must extend the above assignment to include the following:
    1. Draw a filled-square in the center of the applet.
    2. Use a KeyListener to move the square around when some combination of keys are pressed.
    3. Sample Keybinding: 'w' = up, 's' = down, 'a' = left', and 'd' = right. So when these keys are pressed, the square's location should be updated accordingly.

    Must install Java to see this applet.