CIT591 Assignment 1: Portrait
Fall 2008, David Matuszek
Use Eclipse to create a portrait of your partner. You can do this with the Java commands listed below, modifying the numbers as necessary.
In today's lab I will step you through using Eclipse to create a couple of simple programs. This should only take about half an hour. After this, I will get you started on the assignment; do as much as you can in the lab, then finish on your own after the lab.
Since we haven't yet had a chance to do much with Java in class, you will just let Eclipse create a simple program for you, and add one line to it. One thing you need to know in advance is that capitalization matters. Capitalize everything in the program exactly as shown.
System.out.println("Hello
world!");This should get you started.
Create a project named PortraitProject. Within that
project, create a package called portrait. Within that package,
create an applet class called Portrait. Use these exact
names, with the correct capitalization. Use the following code to get
started:
package portrait;
import java.awt.*;
import javax.swing.*;
public class MyPortrait extends JApplet {
public void paint(Graphics g) {
// Replace this line with your drawing commands
}
}
Add code to this applet to draw a picture of your partner. Try to make it
recognizable if at all possible (not just a smiley face,
)
You will not be graded on artistic merit, but you
may lose points if it looks like you didn't even make an effort. Use
drawString commands to put your partner's name at the bottom of
the applet, with by Your Name right below it.
The variable g is the "Graphics" that you are
drawing on, and is a part of every drawing command.
The named colors you can use are RED, ORANGE,
YELLOW, GREEN, CYAN,
BLUE, PINK, MAGENTA,
BLACK, DARK_GRAY, GRAY,
LIGHT_GRAY, and WHITE. (You can create other
colors, but these are the only ones that have names.) For more colors, see
http://houseof3d.com/pete/applets/tools/colors/.
Java uses an X-Y coordinate system, where the units are pixels (picture elements, usually about 72 pixels per inch). X=0, Y=0 is the top left corner of the applet window. If the applet window is 400 pixels wide and 300 pixels high, then the bottom right corner is X=399, Y=299. It's okay to draw things larger than the window, but only the part visible "through the window" will be visible on the screen.
Most of the drawing commands take place within a rectangle defined by (x, y, width, height), where x and y are the coordinates of the top left corner of the rectangle. In algebra, increasing values of y are "higher" in a graph; but in Java, increasing y moves you down on the screen.
Here is a brief explanation of the commands you can use in the applet. (If you want a more detailed explanation, take your browser to http://java.sun.com/javase/6/docs/api/, click on java.awt in the upper left pane, then click on Graphics in the lower left pane. The large pane on the right will show detailed explanations of these and other commands.)
|
PortraitProjectportraitpublic class Portrait extends JApplet
public void paint(Graphics g)PortraitProject_yourNameFor this assignment, you only need to turn in the one file,
which should be named Portrait.java.
Most class assignments will be done by teams, but this one you should do by yourself. You can get help from your classmates, and you should help your classmates if they ask you to, but basically you should do the work yourself.
Thursday, January 22, before midnight. Turn in your program electronically, using Blackboard. (See my Instructions for Using Zip Files and Blackboard). Only assignments submitted via Blackboard will be accepted--do not send your program by email. On this and all subsequent assignments, a late penalty of 5 points per day (out of 100 points) will apply.