/** ++++++++++ ShadowText applet 1.1 Copyright 2000, 2001 virtig01 ++++++++++ !!! ShadowText is protected under the GNU General Public License !!! !!! See http://www.gnu.org/copyleft/gpl.html for details !!! ---------------------------------------------------------------------------- Description: ShadowText is a simple applet that draws a shadow behind text. ShadowText Main Page: http://virtig01.cjb.net/applets/shadowText/ ---------------------------------------------------------------------------- [2001.07.02 10:00 EST] */ import java.awt.*; //Needed for all painting operations public class ShadowText extends java.applet.Applet { String text = "Hi Mom!"; //Holds text from "text" parameter; initial value is "Hi Mom!" Color bgColor = Color.white; //Holds color from "bgcolor" parameter; initial value is white Color fgColor = Color.black; //Holds color from "textcolor" parameter; initial value is black String font = "Times Roman"; //Holds font name from "font" parameter; initial value is "Times Roman" int size; //For text size; initial value is 36 int shadowX = 4; //For X (horizontal) pixel-change alignment of shadow; initial value is 4 int shadowY = 4; //For Y (vertical) pixel-change alignment of shadow; initial value is 4 int textX, textY; //For horizontal and vertical cetering of text public void init() { //Get words String TextValue = getParameter("text"); //Puts the value from the "text" parameter into a string if (TextValue != null) text = TextValue; //If not null (empty), use "TextValue" for "text" //Do color; almost the same process as the text String bgValue = getParameter("bgcolor"); if (bgValue != null) bgColor = new Color(Integer.parseInt(bgValue,16)); //Gets (parses) the hex color from the returned string setBackground(bgColor); //Sets applet background String fgValue = getParameter("textcolor"); if (fgValue != null) fgColor = new Color(Integer.parseInt(fgValue,16)); //Get Font Type; almost the same process as the text; defaults to Times Roman String fontValue = getParameter("font"); if (fontValue != null) font = fontValue; //Get Font Size String sizeValue = getParameter("size"); if (sizeValue != null) size = Integer.parseInt(sizeValue); //Parses value of string in normal (base 10) number format //Get Shadow X&Y Size; Gets the desired distance of the shadow from the text String shadowXValue = getParameter("shadowX"); if (shadowXValue != null) shadowX = Integer.parseInt(shadowXValue); String shadowYValue = getParameter("shadowY"); if (shadowYValue != null) shadowY = Integer.parseInt(shadowYValue); } public void paint(Graphics screen) { //Define font; Set font and color Font defaultFont = new Font(font, Font.BOLD, size); //Defines font using String "font" and int "size" screen.setFont(defaultFont); //Sets the current font to be "defaultFont" screen.setColor(Color.lightGray); //Sets the current screen color (foreground) to a shadowy gray //Do FontMetrics FontMetrics fm = getFontMetrics(defaultFont); //Gets a bunch of useful values about the defaultFont; values stored in "fm" textX = getSize().width / 2 - fm.stringWidth(text) / 2; //To center text horizontally textY = getSize().height / 2 + fm.getHeight() / 3; //To center text vertically showStatus("ShadowText applet from virtig01.cjb.net"); //Status box author branding //Display text with shadow screen.drawString(text, textX-shadowX, textY-shadowY); //Paint the shadow offcenter using pixel-change variables screen.setColor(fgColor); //Sets current screen color to fgColor screen.drawString(text, textX, textY); //Paint text centered on the screen } }