The day after these are assigned we will cover solutions in class. After that, I will post the
- In the last hour of lab, try to complete as much of the following assignments possible.
- When you are finished with an assignment, have either a TA or me come by to check your work.
- Do not hesitate to ask for help from myself or the TA's!
- 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:
Note that there is much in the Events/Listeners sample code
that neeeds to be removed and/or altered for this to work properly!
- Start with the Events/Listeners sample code, listed under the
Core Java examples on the website.
- Your applet should draw a cross-hair wherever the mouse goes
on the applet.
- To do this, review the notes about Events (specifically
MouseMotion events), as well as documentation for drawing to
- The canvas is a Graphics object, whose documentation is
Which methods look like they might be usefull?
Mouse around the area below for a demonstration:
- Working with Events Part 2 For this assignment, you must
extend the above assignment to include the following:
- Draw a filled-square in the center of the applet.
- Use a KeyListener to move the square around when some
combination of keys are pressed.
- 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.