For Lab 6, you'll use your newly developed skills in drawing objects in applets to produce a drawing of your favorite cartoon character, concept, or object in the real world. The requirements are:
Options: Draw a polygon, a String, an Arc (pacman or piece of pie), or rounded rectangle (see code at bottom)
At the top of the file, place the following lines of comments:
// FileName.java
// by Your Name
// CS1301
// Lab #
// Date
Due Tuesday, October 25, ONLINE at the beginning of class. Make sure to save in a folder (if using a USB drive) called cs1301/lab6/, as well as in a folder on your P: drive called P:\web\cs1301\lab6. Link to the applet HTM file from your CS 1301 home page - we will go over this once more at the beginning of class.
drawing polygons (inside a JApplet):
int xPoints[] = { 42, 52, 72, 52, 60, 40, 15,
28, 9, 32, 42};
int yPoints[] = { 38, 62, 68, 80,105, 85,102, 75, 58, 60, 38};
public void paint(Graphics gr)
{
gr.setColor(Color.red);
gr.drawPolygon(xPoints, yPoints, xPoints.length); // .fillPolygon
to shade in
}
// Note: xPoints and yPoints are lists of the x and y
coordinates of the polygon in question
// The above example draws a star starting and ending with the point (42, 38)
Drawing Strings:
public void paint(Graphics gr)
{
gr.setColor(Color.blue);
gr.drawString("Text here", 40, 140); // x, y
}
Drawing Arcs:
public void paint(Graphics gr)
{
gr.setColor(Color.red);
gr.drawArc(10,50,100,100,20,320); // x, y, width,
height, start angle, sweep angle
// fill, too
}
Drawing Rounded Rectangles:
public void paint(Graphics gr)
{
gr.setColor(Color.red);
gr.drawRoundRect(220, 20, 80, 80, 40, 40); // x, y,
width, height, corner roundness x 2
// fill, too
}