|
InheritanceExercise
BasicString.java
import java.awt.*;
/**
* BasicString class
*
* @author Chuck Cusack
* @version 1.0, September, 2006
*/
public class BasicString
{
private int x;
private int y;
private Color color;
private String myString;
/**
* The defualt constructor, which creates a 0 by 0 object at (0,0)
* that is white and not filled.
*/
public BasicString() {
setLocation(0,0);
setColor(Color.black);
setString("");
}
public BasicString(int x, int y,Color color, String myString) {
setLocation(x,y);
setColor(color);
setString(myString);
}
/*
* The standard get and set methods
*/
public void setString(String s) {
myString=s;
}
public String getString() {
return myString;
}
public void setColor(Color color) {
this.color=color;
}
public Color getColor() {
return color;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x=x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y=y;
}
public void setLocation(int x,int y) {
setX(x);
setY(y);
}
/**
* Overriding drawObject from GraphicalObject so it actually
* draws something.
*/
public void drawObject(Graphics g) {
// Save the current color so we can reset it when we are done
Color oldColor=g.getColor();
g.setColor(this.getColor());
g.drawString(getString(),x,y);
// Reset the color back to the original.
g.setColor(oldColor);
}
}
|