CIT591 Assignment 7: Self
Portrait
Fall 2011, 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, following this outline. This should take about half the period. After this, I will get you started on the self portrait assignment.
Create a project named SelfPortrait. Within that
project, create a package called selfPortrait. Within that package,
create a class called SelfPortrait. Use these exact
names, paying attention to the capitalization. Use the following code to get
started:
package selfPortrait;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
/**
* @author Put your name here
*/
public class SelfPortrait extends JFrame {
public static void main(String[] args) {
new SelfPortrait().run();
}
private void run() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 300);
setVisible(true);
}
public void paint(Graphics g) {
g.drawString("Put your name here", 100, 280);
g.setColor(Color.RED);
g.fillRect(10, 27, 280, 10);
g.setColor(Color.ORANGE);
g.fillOval(100, 100, 100, 120);
}
}
This program is just to get you started; change it as much as you like. Your goal is to draw a picture of yourself. 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 a
drawString command to put your name at the bottom of the
window.
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 predefined 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 window. If the 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 your program. (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.)
|
SelfPortrait.java.
Do this assignment 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.
Before 6 AM, Friday November 4, via Sakai.