DrawingObj
* interface. This particular class enables a test string to be displayed
* on the drawing panel with a shadowing effect.
* For example, the following lines initializes an instance of this class
* and display a text string "Hello" on the drawing panel with blue text color
* and gray shadow at position (100, 100):
* ShadowLabel helloLabel = new ShadowLabel("Hello");
* drawingPanel.addDrawingObj(helloLabel);
* helloLabel.move(100, 100);
* helloLabel.setColor(Color.blue);
* drawingPanel.redraw();
*
* This object can be removed from the drawing panel by using the
* removeObj
method from DrawingPanel
.
* @see DrawingPanel#removeObj
*/
public class ShadowLabel extends Drawable {
private Font font;
private Color text_col = Color.black;
/**
* Set the text color of the drawing object.
* @param col The new text color of the object.
*/
public void setColor( Color col ) {
this.text_col = col;
}
/**
* Get the text string for this label object.
* @return the text string for this label object.
*/
public String getText() {
return new String(label);
}
/**
* Construct a new shadow label with the initial text string as
* specified by the parameter.
* @param str The initial text string for this shadow label.
**/
public ShadowLabel(String str) {
this.label = str;
font = new Font("Helvetica", Font.BOLD, 14);
}
public Font getFont() { return font; }
/**
* Draw the text string with a gray label. This method is normally
* called from the drawing panel paint method.
*/
public void draw(Graphics g) {
g.setFont(font);
g.setColor(Color.lightGray);
g.drawString(label, x+1, y+1);
g.setColor(text_col);
g.drawString(label, x, y);
}
}