|
| Homework 4DetailsPurpose
The purpose of the first assignment is to
- Help you refresh your memory on Java programming
- Familiarize yourself with the
Eclipse IDE (integrated development environment),
- Learn how to use the Java API (application programming interface).
There is not a serious design component to this assignment, and at the surface
it does not appear to be closely related to the main concepts of the course.
However, it is meant to be a fun assignment to get you back into the swing of Java programming, and it turns out it does have a little to do with a few of the topics we will talk about.
Overview:
- Get the code
- Update width/height/title:
The width and height of the window and the title should be changed near the top of InteractivePicture. You should make no other changes to that file.
- Draw a picture: Modify the code in PicturePanel to draw a picture, making sure to follow all of the guidelines below.
- Evaluate yourself: Fill in the MyGrade.txt file. Specify the score you think you earned in each category and briefly justify.
- Share folder: If you have not already shared a Google folder with me, create a folder called Smith_Programs (but with your last name instead of Smith) in your Google Drive and share it with me. Make sure to use your 1Hope account.
- Submit your code:
- Create a new directory HW4 in the Google folder you shared with me (named Smith_Programs, but with your last name instead of Smith).
- Copy the entire SmithPicture directory (again, with your name instead) into the HW 4 directory.
Get the code:
- Download BlankPicture.zip
- Unzip to somewhere you can find it. It will unzip into folder BlankPicture
- Rename BlankPicture to SmithPicture, where you replace Smith with your name
- Import it into Eclipse:
- Click File-->Import...
- Choose Existing Projects into Workspace and click Next
- Browse to the SmithPicture (or whatever you renamed it)
- Click Finish
- The project should now be in your workspace.
Assignment
For this assignment you need to finish the implementation of the class PicturePanel.java that draws a picture.
I will let you decide exactly what you want to draw, but be creative.
You can draw a picture of yourself, your dog, a car, a park, etc.
Your drawing should be a reflection of yourself.
I can help you brainstorm ideas if necessary.
At a minimum, you must:
- Have at least several dozen objects (circles, lines, text, etc.).
This does not include stuff drawn in loops. In other words, you should have at least 24 statements
in your code like drawOval, fillRect, etc.
- Utilize several colors.
- Have some text, including your name in the lower right corner. Use different fonts and styles.
- Use several loops, and at least one nested loop (That is, a loop within a loop) to draw something.
- Use at least a few if-then-else statements.
- Use an array, ArrayList, or another simple data structure.
- Use at least two methods.
- React to at least 2 different mouse events. It does not count to react to "clicks" with both mouseClicked and mousePressed.
Use another interaction like dragging.
(Note: There are two sorts of mouse events:
MouseEvents and MouseMotionEvents. See below for more about these.)
- Create one or more new classes (not including listeners).
- Change the title of the frame so it relates to your drawing.
The more different sorts of objects you use, the better.
Your grade will be based not only on how creative you are,
but how much effort you put into learning some
things about the various parts of the Java API mentioned below.
An assignment which meets the expectation will receive 24/30.
Scoring higher than this will require you to go beyond the minimum requirements.
If you have some prior experience with Java, or learn quickly, try to make your
application fancy with animation, or adding some functionality. For instance, you
can ask the viewer to input some information, and modify the drawing based on the input.
You should not use BlueJ for this project.
Use Eclipse instead.
Make sure to update the documentation.
Remove my helpful comments and add appropriate comments to each class and method, using Javadoc-style comments.
Also add inline comments within longer methods to describe what portions of your code are doing.
Resources
-
Past Student Solutions
(including mine).
Several examples I and previous students wrote.
Download the file, unzip it somewhere on your computer, and import it in the same way as you did the SmithPicture.
It will add 16 projects to your workspace.
You can see the code and run them (Right-click their copy of InteractivePicture and select Run As--Java Application).
When you are done with the assignment, you can delete those projects, but don't delete yours!
- TimerExample A simple example of using a timer to do animation.
- Java API
Here are the classes that will be of most interest to you for this assignment (these link to the Java 6 versions of these classes,
but they should be not much different than the Java 7 or 8 versions).
- Graphics
The main class you will be interested in. You draw using the methods from this class.
- Color
A class you may be interested in if you want to create your own colors.
- Font
A class you may be interested in if you want to do anything fancy with Fonts.
- MouseMotionListener
An interface for mouse motion events
- MouseListener
An interface for mouse events
- MouseAdapter
An adapter that implements the MouseListener interface. Extend this class as a way to handle mouse events.
Simply override any of the 5 methods to have it react the way you want.
- MouseEvent
The event passed to the MouseAdapter/MouseListener. Notice it allows you to determine the
x and y coordinates of the mouse position, which button was clicked, etc.
- Java Fonts
A simple applet that shows you what certain fonts look like in Java. You might find it useful.
- Google (link includes a sample search). Search for whatever you need help with. For instance
"Java fonts" or "java font choices" or "java create colors", etc. When I am looking for a java class, I search for "java blah 8" (If the class is "blah") and the first hit is usually the API for that class (The "8" ensures I get the documentation for Java 8 instead of 1.4.2 or 7 or some other version).
Grades
Grades will be based on the following chart. See the Grading page for how to interpret these categories.
| Criteria | Points | Details |
| Correctness | 10 | Each requirement met (8) and it runs (2) |
| Style | 6 | Reasonable variable/method names, methods make sense, and code formatting (2 each) |
| Documentation | 6 | The class, each method, and code is documented (2 each) |
| Learning Gains | 8 | Used classes, made an elaborate drawing, included extra events and methods (especially if it involved keyboard and other event types), used other new things (2 each) |
| Total | 30 | |
|
|
|