Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
For all three browsers, we’ll use the same applet, called Renegade. Renegade isn’t really dangerous, but it does try to find out your name, using System.getProperty("user.name"). This action is not allowed in the applet sandbox, to protect the privacy of the user. In Renegade, we enclose this call in a try block in case a SecurityException is thrown. Save the source code for this class in Renegade.java.
import java.applet.*;
import java.awt.*;
public class Renegade extends Applet {
private String mMessage;
public void init() {
try {
mMessage = "Your name is " + System.getProperty("user.name") + ".";
}
catch (SecurityException e) {
mMessage = "Can't get your name, due to a SecurityException.";
}
}
public void paint(Graphics g) {
g.drawString("Renegade", 25, 25);
g.drawString(mMessage, 25, 50);
}
}