Starting with init()

The init() method of an applet automatically is handled once when the applet first starts to run. In this example, this method is used to assign values to the two arrays created for this applet, pageTitle and pageLink. It also is used to create a clickable button that will appear on the applet. The method consists of the following statements:

public void init() {
 pageTitle[0] = "Sun's Java site";
 pageLink[0] = getURL("");
 pageTitle[1] = "Cafe au Lait";
 pageLink[1] = getURL("");
 pageTitle[2] = "JavaWorld";
 pageLink[2] = getURL("");
 pageTitle[3] = "Java 2 in 24 Hours";
 pageLink[3] = getURL("");
 pageTitle[4] = "Sams Publishing";
 pageLink[4] = getURL("http://www.");
 pageTitle[5] = "Workbench";
 pageLink[5] = getURL("");
 Button goButton = new Button("Go");
 FlowLayout flow = new FlowLayout();

Strings are assigned to the six elements of the pageTitle array, which stores the title of each web page. The elements of the pageLink array are assigned a value returned by the getURL() method, which you will be creating for this program. The last seven statements of the init() method are used to create a button and place it on the applet window. The button has the name goButton and is labeled with the text Go.