CSE 341 -- Programming LanguagesSpring 1999 |
Department of Computer Science and Engineering, University of WashingtonSteve Tanimoto (instructor) and Jeremy Baer (teaching assistant). |
Assignment J1 |
Java WarmupDue date and time: Friday, April 9, 1999, by 12:15 (just prior to class).Instructions for turning in your work will be posted later. |
Implement a drawing program in Java.
Here are some ideas for getting started: (a) study the BallWorld program in Budd. Understand how the paint method works and what you need to do to get graphics up on the screen. (b) think about how a vector (see Budd on Java's Vector class, page 100) could be used to store a succession of mouse positions corresponding to dots of ink or to vertices of a polyline). (c) look and see how you can detect mousePressed and mouseReleased events by subclassing the MouseAdapter class (Budd, page 101).
Here is the minimum functionality you should support:
1. Bring up a frame that has a drawing area. (If you wish, create
an applet and you won't need a separate frame.)
2. Detect mousePressed events (or, if you prefer, mouseDragged events)
and cause something to be drawn at the current mouse position whenever
the mouse is pressed within the drawing area.
3. The ink marks or whatever the user is drawing should accumulate
as s/he draws more and more of them.
4. If the user picks up the frame (window) and moves it or resizes
in, the program should correctly repaint the screen with the current drawing.
Here's an applet that shows the minimum functionality. To start a new
painting, reload the applet. (In Netscape Navigator, you reload the
applet by holding down the shift key while clicking on Reload.)
Optional functionality:
5. Provide a way for the user to erase the screen without restarting
the program.
6. Provide a way for the user to erase selectively within the current
drawing.
7. Provide a way for the user to change the color of what is being
drawn.
8. Provide a way to change the brush size or pen size.
Programming style: Define your classes carefully. Comment your
code. Explain (in your comments) where you are using inheritance.
Explain (in your comments) where you are providing a method that overrides
the one that would be inherited. Choose identifier names carefully.
Use appropriate indentation and other formatting. Make your code
easy to read and understand.