![]() |
Lab 12
|
Certain methods run automatically:
import java.applet.*;import java.awt.*; // graphics library in Java Abstract Windows Toolkit
public void drawLine (int x1, int y1, int x2, int y2)public void drawRect (int x, int y, int width, int height)public void fillRect (int x, int y, int width, int height)public void setColor (Color c)public void drawOval (int x, int y, int width, int height)public void fillOval (int x, int y, int width, int height)public void drawArc (int x, int y, int width, int height, int startAngle, int arcAngle)public void fillArc (int x, int y, int width, int height, int startAngle, int arcAngle)
![]() |
![]() |
Polygon splotch = new Polygon();
Then, we add the points one by one (you can add as many as you like):
splotch.addPoint(200,185);...
And then we can draw the object we created:
g.drawPolygon(splotch);
Your task today is to
create your self-portrait.
You must use (at least) the following six methods:
setColor()
you
use setFont()
(see the Graphics contract). Changing your font
requires creating a new Font
object. The
Font
constructor takes 3 parameters:
Font rainfont = new Font("Serif", Font.BOLD, 20);
Want to know more? Font
class in the
Font contract.
Experiment with different font names, styles, and sizes! printFontList()
from your
paint()
method in the SelfPortrait class
. It will print a list of all the available fonts
to your console window.
You can change the text color by setting the color of the Graphics object. Click here for more information about available colors and how to make up your own color! Download the lab12_programs folder to get started.
We'll display your
results in a cs111 gallery online. Goofy prizes for the best ones!
Click here for previous cs111 student self portraits.
Want to know more? Check out the Java Graphics Contract