FileDocCategorySizeDatePackage
MailtoButton.javaAPI DocExample3909Sun Feb 08 21:33:48 GMT 2004None

MailtoButton

public class MailtoButton extends Applet
MailtoButton -- look like a mailto, but not visible to spiders.
author
Copyright 1995, 1997 Ian F. Darwin, http://www.darwinsys.com/, http://www.darwinsys.com.
version
$Id: MailtoButton.java,v 1.5 2004/02/09 03:33:48 ian Exp $

Fields Summary
protected String
label
The label that is to appear in the button
protected int
width
The width and height
protected int
height
protected String
targetName
The string form of the URL to jump to
protected String
targetHost
protected URL
targetURL
The URL to jump to when the button is pushed.
protected String
fontName
The name of the font
protected String
DEFAULTFONTNAME
protected Font
theFont
The font
protected int
fontSize
The size of the font
private String
TARGET1
The HTML PARAM for the user account -- keep it short
private String
TARGET2
The HTML PARAM for the hostname -- keep it short
private String
BOGON1
private String
BOGON2
private String
subject
The string for the Subject line, if any
Constructors Summary
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 voidinit()
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);