CS 120
Fall 2016, Instructor: Jeffrey
Horn
Assignment
4: "Methods
(and Re-locatable Graphics)"
Handed out:
Tuesday, September 20, 2016
Due: Wednesday,
September 28, 2016
Purpose:
Learn
- The fundamentals of writing and using methods:
- Method signature (name, parameters), method body
- How to invoke a method
- Scope of parameters
- THE simplest technique for making your graphics relocatable! (i.e.,
creating translation parameters (e.g., x and y)
Reading: (from
online textbook)
-
GUI Java: Ch.
2 of our online text.
Details:
- This is like A3 except you need to have a
separate method for your graphics.
- The signature of this method must be:
- "private
void paintTarget(Graphics g, int x, int y)"
- although you can name your parameters
anything you'd like!
- Your graphics code must be at least 20 lines
long. (This is to ensure that you have a sufficiently complex
graphic!)
- Your graphics item
must be no larger than 40 by 40 pixels. Specifically it must fit
inside the 40 by 40 pixel square whose upperleft corner is given by
the x,y input parameter values.
- Your graphic item must be colorful! (Say
minimum of three different colors. Black counts as one, but white
does not! White will be our background color.)
- Test your code by invoking your paintTarget
method with different values of x and y (e.g., use your A3 code).
- Email me your paintTarget method in the
body of an email message to jhorn@nmu.edu with the SUBJECT line: "CS120: A4".