Applet notinited
I am trying to create an applet, but at the bottom of the screen (in the status bar) it says "Applet CheckerboardPatterns notinited". I am using some examples from my textbook, but I still cannot see what I am doing wrong. Any help is appreciated.
import java.awt.*;
import javax.swing.*;
public class CheckerboardPatterns extends JApplet
{
enum SquareColor{red, blue};
enum Squares{Square1, Square2, Square3, Square4, Square5, Square6,
Square7, Square8};
enum Patterns{shells, diagonals};
Patterns pattern;
Patterns currentPattern;
public void init()
{
int sideSize = (int)(3 + Math.random() * 6);
//int patternType = (int)(Math.random() * 2);
int patternType = 1;
int size = sideSize * sideSize;
switch (patternType)
{
case 0:
pattern = Patterns.diagonals;
break;
case 1:
pattern = Patterns.shells;
break;
}
}
public void paint(Graphics graphics)
{
switch(pattern)
{
case diagonals:
paintDiagonals(graphics);
break;
case shells:
// paintShells(graphics);
break;
}
final int LEFT_MARGIN = 50, TOP_MARGIN = 50, X_OFFSET = 5, Y_OFFSET = 15,
NAME_INDENT = 50;
graphics.drawString("Pattern: " + currentPattern.name(), LEFT_MARGIN + NAME_INDENT,
TOP_MARGIN - Y_OFFSET);
}
/*
private void paintShells(Graphics graphics)
{
}
*/
private void paintDiagonals(Graphics graphics)
{
String rowColNumber;
for (Squares row: Squares.values())
for (Squares col: Squares.values())
{
rowColNumber = "" + (row.ordinal() + 1) + "" + (col.ordinal() + 1);
paintSquare(graphics, row.ordinal(), col.ordinal(), rowColNumber);
}
}
private void paintSquare(Graphics graphics, int row, int col,
String label)
{
final int SIZE = 30;
int x = (col + 1) * SIZE, y = (row + 1) * SIZE, diagonal = row + col;
switch (diagonal % 2)
{
case 0:
graphics.setColor(Color.red);
break;
case 1:
graphics.setColor(Color.blue);
break;
}
graphics.fillRect(x, y, SIZE, SIZE);
graphics.setColor(Color.white);
x += SIZE / 4;
y += SIZE / 2;
graphics.drawString(label, x, y);
}
}
[2531 byte] By [
ericelysia] at [2007-11-11 10:20:19]

# 1 Re: Applet notinited
OK, I have fixed my path and class path. Heres what they are set to:
Environment Variables
User Variables
CLASSPATH=.;C:\Program Files\Java\jre1.6.0\bin;C:\java
PATH=C:\Program Files\Java\jdk1.6.0\bin
System Variables
CLASSPATH=.;C:\Program Files\Java\jre1.6.0\lib\ext\QTJava.zip
Path=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\QuickTime\QTSystem\;c:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Java\jdk1.6.0\bin
At http://java.sun.com/developer/onlineTraining/new2java/ it shows an html file with the .class at the end:
<HTML>
<BODY>
<APPLET CODE=SimpleApplet.class WIDTH=200 HEIGHT=100>
</APPLET>
</BODY>
</HTML>
I took the .class out of my html file and I am still getting this in the Java Console:
Java Plug-in 1.6.0
Using JRE version 1.6.0 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\Joe
----------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
p: reload proxy configuration
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------
load: class CheckerboardPatterns not found.
java.lang.ClassNotFoundException: CheckerboardPatterns
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadCode(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: C:\CheckerboardPatterns.class (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
at sun.applet.AppletClassLoader.getBytes(Unknown Source)
at sun.applet.AppletClassLoader.access$100(Unknown Source)
at sun.applet.AppletClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 10 more
I cannot figure out why I'm still getting the Applet CheckerboardPatterns notinited.