java.lang.ArrayIndexOutOfBoundsException: 6
While trying to learn how to make applets I tried to make a homepage for myself with revolving links.
It compiled just fine but when I try to open it in firefox or appletviewer it gives me the error:
java.lang.ArrayIndexOutOfBoundsException: 6
This is my code.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
Code:
public class Revolve extends JApplet
implements Runnable, ActionListener {
String pageTitle[] = new String[6];
URL pageLink[] = new URL[6];
int current = 0;
Thread runner;
public void init() {
Color background = new Color(255,255,204);
setBackground(background);
pageTitle[0] = "Facebook";
pageLink[0] = getURL("http://www.facebook.com");
pageTitle[1] = "Hotmail";
pageLink[1] = getURL("http://www.hotmail.com");
pageTitle[2] = "Youtube.com";
pageLink[2] = getURL("http://www.youtube.com");
pageTitle[3] = "Google";
pageLink[3] = getURL("http://www.google.com");
pageTitle[4] = "My Life Is Average";
pageLink[4] = getURL("http://www.mylifeisaverage.com");
pageTitle[5] = "I Can Has Cheezeburger";
pageLink[5] = getURL("http://www.icanhascheezeburger.com");
pageTitle[6] = "Albino Blacksheep";
pageLink[6] = getURL("http://www.albinoblacksheep.com");
Button goButton = new Button("Go");
goButton.addActionListener(this);
FlowLayout flow = new FlowLayout();
Container pane = getContentPane();
pane.setLayout(flow);
pane.add(goButton);
setContentPane(pane);
}
URL getURL(String urlText) {
URL pageURL = null;
try {
pageURL = new URL(getDocumentBase(), urlText);
}
catch (MalformedURLException m) { }
return pageURL;
}
public void paint(Graphics screen) {
super.paint(screen);
Graphics2D screen2D = (Graphics2D) screen;
screen2D.drawString(pageTitle[current], 5, 60);
screen2D.drawString("" + pageLink[current], 5, 80);
}
public void start() {
if (runner == null) {
runner = new Thread(this);
runner.start();
}
}
public void run() {
Thread thisThread = Thread.currentThread();
while (runner == thisThread) {
repaint();
current++;
if (current > 5)
current = 0;
try {
Thread.sleep(10000);
} catch (InterruptedException e) { }
}
}
public void stop() {
if (runner != null) {
runner = null;
}
}
public void actionPerformed(ActionEvent evt) {
if (runner != null) {
runner = null;
}
AppletContext browser = getAppletContext();
if (pageLink[current] != null)
browser.showDocument(pageLink[current]);
}
}
Also, could there be something wrong with my html?
Code:
<html>
<head>
<title>Paul's Home Page</title>
</head>
<body bgcolor="#C4C4C4">
<font face="Arial" size=3>
<table>
<tr>
<td bgcolor="#FFCCFF" width=300 valign="TOP" align="CENTER">
<h2>Paul's Home Page</h2>
<p>Welcome! This page is under construction.
</td>
<td bgcolor="#FFFFCC" width=200 valigh="TOP" align="RIGHT">
<i><b>Some of my favorite links:</b></i>
<applet code="Revolve.class" height=100 width=200>
</applet>
<center>
<i>Click to visit</i>
</center>
</td>
</tr>
</table>
</font>
</body>
</html>