DropShadowpublic class DropShadow extends Applet DropShadow -- show overlapped painting. |
Fields Summary |
---|
protected String | theLabelThe label that is to appear in the window | protected int | widthThe width and height | protected int | height | protected String | fontNameThe name of the font | protected Font | theFontThe font | protected int | fontSizeThe size of the font | protected int | theOffsetThe offset for the drop shadow | protected boolean | inittedOKTrue if we got all required parameters |
Methods Summary |
---|
public java.lang.String[][] | getParameterInfo()Give Parameter info to the AppletViewer, just for those
writing HTML without hardcopy documentation :-)
String info[][] = {
{ "label", "string", "Text to display" },
{ "fontname", "name", "Font to display it in" },
{ "fontsize", "10-30?", "Size to display it at" },
};
return info;
| public void | init()Called from the browser to set up. We want to throw various
kinds of exceptions but the API predefines that we don't, so we
limit ourselves to the ubiquitous IllegalArgumentException.
// System.out.println("In DropShadow init()");
theLabel = getParameter("label");
if (theLabel == null)
throw new IllegalArgumentException("LABEL is REQUIRED");
// Now handle font stuff.
fontName = getParameter("fontname");
if (fontName == null)
throw new IllegalArgumentException("FONTNAME is REQUIRED");
String s;
if ((s = getParameter("fontsize")) != null)
fontSize = Integer.parseInt(s);
if (fontName != null || fontSize != 0) {
theFont = new Font(fontName, Font.BOLD + Font.ITALIC, fontSize);
System.out.println("Name " + fontName + ", font " + theFont);
}
if ((s = getParameter("offset")) != null)
theOffset = Integer.parseInt(s);
setBackground(Color.green);
inittedOK = true;
| public void | paint(java.awt.Graphics g)Paint method showing drop shadow effect
if (!inittedOK)
return;
g.setFont(theFont);
g.setColor(Color.black);
g.drawString(theLabel, theOffset+30, theOffset+50);
g.setColor(Color.white);
g.drawString(theLabel, 30, 50);
|
|