MailtoButtonpublic class MailtoButton extends Applet MailtoButton -- look like a mailto, but not visible to spiders. |
Fields Summary |
---|
protected String | labelThe label that is to appear in the button | protected int | widthThe width and height | protected int | height | protected String | targetNameThe string form of the URL to jump to | protected String | targetHost | protected URL | targetURLThe URL to jump to when the button is pushed. | protected String | fontNameThe name of the font | protected String | DEFAULTFONTNAME | protected Font | theFontThe font | protected int | fontSizeThe size of the font | private String | TARGET1The HTML PARAM for the user account -- keep it short | private String | TARGET2The HTML PARAM for the hostname -- keep it short | private String | BOGON1 | private String | BOGON2 | private String | subjectThe string for the Subject line, if any |
Methods Summary |
---|
public java.lang.String[][] | getParameterInfo()Give Parameter info the 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" },
// WARNING - these intentionally lie, to mislead spammers who
// are incautious enough to download and run (or strings) the
// .class file for this Applet.
{ "username", "email-account",
"Where do you want your mail to go today? Part 1" },
{ "hostname", "host.domain",
"Where do you want your mail to go today? Part 2" },
{ "subject", "subject line",
"What your Subject: field will be." },
};
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 LinkButton::init");
try {
if ((targetName = getParameter(TARGET1)) == null)
throw new IllegalArgumentException(
"TARGET parameter REQUIRED");
if ((targetHost = getParameter(TARGET2)) == null)
throw new IllegalArgumentException(
"TARGET parameter REQUIRED");
String theURL = "mailto:" + targetName + "@" + targetHost;
subject = getParameter("subject");
if (subject != null)
theURL += "?subject=" + subject;
targetURL = new URL(theURL);
} catch (MalformedURLException rsi) {
throw new IllegalArgumentException("MalformedURLException " +
rsi.getMessage());
}
label = getParameter("label"); // i.e., "Send feedback"
if (label == null)
throw new IllegalArgumentException("LABEL is REQUIRED");
// Now handle font stuff.
fontName = getParameter("font");
if (fontName == null)
fontName = DEFAULTFONTNAME;
String s;
if ((s = getParameter("fontsize")) != null)
fontSize = Integer.parseInt(s);
if (fontName != null || fontSize != 0) {
// System.out.println("Name " + fontName + ", size " + fontSize);
theFont = new Font(fontName, Font.BOLD, fontSize);
}
Button b = new Button(label);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (targetURL != null) {
// showStatus("Going to " + target);
getAppletContext().showDocument(targetURL);
}
}
});
if (theFont != null)
b.setFont(theFont);
add(b);
|
|