Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

8.1. Renegade

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);
  }
}


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint