The ProfPointing class
is a subclass of Prof class
which is a subclass of the Person class
//filename: ProfPointing.java
import java.awt.*;
public class ProfPointing extends Prof {
// draws the person, anchored at (x,y)
//overriding its inheritance, use its own drawPerson
public void drawPerson (Graphics g, int x, int y) {
// draw head
g.drawOval(x, y, 20, 30);
g.drawOval(x + 11, y + 11, 5, 3); // right eye
g.drawOval(x + 3, y + 11, 5, 3); // left eye
g.drawOval(x + 7, y + 20, 6, 3); // mouth
//draw body
g.drawLine(x + 8, y + 30, x + 8, y + height);
g.drawLine(x + 12, y + 30, x + 12, y + height);
// draw arms
// right arm (appears to the left)
g.drawLine(x + 8, y + 30, x, y + 40);
g.drawLine(x, y + 40, x + 8, y + 50);
// left arm
g.drawLine(x + 12, y + 30, x + 20, y + 40);
g.drawLine(x + 20, y + 40, x + 28, y + 30);
//draw feet
g.fillRect(x, y + height, 10, 3);
g.fillRect(x + 11, y + height, 10, 3);
}
public void drawBBoardInfo(Graphics g, int x, int y, String str) {
drawBBoard(g, x, y);
g.setColor(Color.white);
g.drawString(str, x + 10, y + 45);
}
public void drawProfPointing(Graphics g, int x, int y) {
drawPerson(g, x, y);
drawBBoardInfo(g, x + 25, y + 2, "2 + 3 = ");
}
}
//ProfPointingApplet.java
import java.awt.*;
import java.applet.Applet;
public class ProfPointingApplet extends Applet {
public ProfPointing joe; // Joe is an instance variable.
public void init() {
/* init() is called only once.
This is where the applet is initialized.*/
joe = new ProfPointing(); // Create a new object instance for Joe Hamilton.
}
public void paint ( Graphics g ) {
joe.drawProfPointing(g, 20, 15); // Draw Joe on the applet.
}
}