private Font font : the font use to display the name of the
shape.
private Color color: the color used to draw the shape
private Point center: the center of the shape located.
protected static final Color fontColor: the color used to display
the name, it is black.
protected static final Font defaultFont : the default font used to display the
name. The font name is Dialog, font style is plain, and font size is 12.
public MyShape(Point center, Color color, Font font)public MyShape(Point center, Color color): use the defaultFont for the font .
public static String getName() : return "Shape", the name.
public void setFont(Font font)
public Font getFont()
public void setColor(Color color)
public Color getColor()
public void setCenter(Point center)
public Point getCenter()
public void draw(Graphics g):
draw the name (i.e. "Shape") with Font type font with the lower left corner at
the center. The color of the string is fontColor
.
You can replace MyShape by other class names.javap -private MyShape
static {} , ignore it.
MyShape.
Here are all the members and constructors. You can't add any extra members or
constructors to it.
private int widthprivate int heightpublic MyRectangle(int width, int height, Point center, Color color, Font
font)public MyRectangle(int width, int height, Point center, Color color)
: font is the default font.public static String getName(): return "Rectangle", the name of the shape.public void draw(Graphics g): draw the Rectangle with color
color and center located at center. Again,
the name (i.e. "Rectangle") with Font type font is displayed with the lower left corner at
the center. The color of the string is fontColor.
MyShape.
Here are all the members and constructors. You can't add any extra members or
constructors to it.
private int radiuspublic MyCircle(int radius, Point center, Color color, Font font)public MyCircle(int radius, Point center, Color color):
font is the default font.public static String getName(): return "Circle", the name of the shape.public void draw(Graphics g): draw the circle with color
color and center located at center. Again,
the name (i.e. "Circle") with Font type font is displayed with the lower left corner at
the center. The color of the string is fontColor.
java ShapeTest, a frame will shows up with

| shape | center | color | font |
|---|---|---|---|
| circle, radius = 100 | (150,150) | green | Serif, bold and italic, 30 |
| circle, radius = 70 | (350,100) | orange | default |
| circle, radius = 40 | (250,250) | pink | Monospaced, bold, 15 |
| rectangle, width = 120, height = 50 | (300,300) | red | Dialog, italic, 10 |
| rectangle, width = 150, height = 100 | (100,400) | yellow | default |
| shape | (350,400) | doesn't matter | DialogInput, plain, 40 |
draw methods to draw on Graphics g.
java ShapeTest .
All source code submitted must contain the following information at the beginning of each file:
* Your full name.
* Your student ID number.
* Your PIC login ID.
* Your e-mail address.
* Your discussion section number and TA's name.
* The assignment number and description.
* Honesty pledge.
Properly formatted, this information should appear as follows:
/*
* Name: Charles Li
* Student ID: 000 000 000
* PIC ID: ccli
* E-mail: ccli@math.ucla.edu
* Discussion: 1A, Mike Moore
* Assignment: hw2
*
* I, Charles Li, pledge that this is my own independent work, which
* conforms to the guidelines of academic honesty as described in the course
* syllabus.
*
*/
MyShape.java, MyCircle.java, MyRectangle.java, ShapeTest.java
.