| Assignment 1: Self Portrait Fall 2006, David Matuszek |
Use Eclipse to create a self portrait. 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 self portrait 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 actually talk about 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 is less than we will do in lab, but it should get you started.
Create a project named MyPortraitProject, and create an applet
class called MyPortrait. Use these exact names. Use the following code to get started:
import java.awt.*; import javax.swing.*; public class MyPortrait extends JApplet { public void paint(Graphics g) { // Replace this line with your code } }
Add code to this applet to draw a picture of yourself. Try to make it recognizable if at all possible (not just a smiley face,
)but you will not be graded on artistic merit! It will help if you understand the x-y coordinate system
(described briefly below), but you don't have to understand everything; you
should be able to do this assignment by imitating my applet, copying lines and
changing numbers as necessary. Use a drawString command to put your name at the bottom of the applet.
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 (as in the previous applet), then the bottom right corner is X=400, y=300.
Most of the drawing commands take place within a rectangle defined by (x, y, width, height), where x is the number of pixels in from the left edge and y is the number of pixels down from the top edge. Values outside the applet window are legal, but are not drawn 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/j2se/1.5.0/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.)
|
MyPortrait.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.
September 14, 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. The usual late penalty of 10 points per day (out of 100 points) will apply.