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.*;

publicclass CheckerboardPatternsextends JApplet

{

enum SquareColor{red, blue};

enum Squares{Square1, Square2, Square3, Square4, Square5, Square6,

Square7, Square8};

enum Patterns{shells, diagonals};

Patterns pattern;

Patterns currentPattern;

publicvoid 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;

}

}

publicvoid paint(Graphics graphics)

{

switch(pattern)

{

case diagonals:

paintDiagonals(graphics);

break;

case shells:

//paintShells(graphics);

break;

}

finalint 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)

{

}

*/

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

}

}

privatevoid paintSquare(Graphics graphics,int row,int col,

String label)

{

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

}

}

[4647 byte] By [ericelysiaa] at [2007-11-26 17:30:51]
# 1

Here is what the Java Console shows:

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.class not found.

java.lang.ClassNotFoundException: CheckerboardPatterns.class

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.class (The system cannot find the path 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

ericelysiaa at 2007-7-8 23:58:48 > top of Java-index,Java Essentials,New To Java...
# 2
You don't have to put the '.class' at the end when you invoke the appletviewer/embed in HTML.Java interprets the dot and "class" at the end as the "class" class inside the CheckerboardPatterns package. I don't think that's what you meant, though.
kevjavaa at 2007-7-8 23:58:48 > top of Java-index,Java Essentials,New To Java...
# 3

In the process of trying to figure this out, I have changed my Environment Variables. Here is what I have:

End User Variables:

CLASSPATH

.;C:\java

PATH

C:\Program Files\Java\jdk1.6.0\bin;C:\java

System Variables:

CLASSPATH

.;C:\Program Files\Java\jre1.6.0\lib\ext\QTJava.zip;C:\java

Path

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\QuickTime\QTSystem\;c:\Program Files\Microsoft SQL Server\90\Tools\binn\

ericelysiaa at 2007-7-8 23:58:48 > top of Java-index,Java Essentials,New To Java...
# 4

OK, I have fixed my path and class path. Here抯 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.

ericelysiaa at 2007-7-8 23:58:48 > top of Java-index,Java Essentials,New To Java...
# 5

> At http://java.sun.com/developer/onlineTraining/new2java/

> it shows an html file with the .class at the end:

That's curious indeed. I've never needed the .class extension in the HTML file.

Actually, I usually use the .jar files. They're a little easier to manage and somewhat more predictable with respect to behavior.

http://java.sun.com/j2se/1.4.2/docs/guide/misc/applet.html

This page also says to use the .class as well, so it may not be incorrect after all. However, the page needs to know where to look for the files. I would recommend adding the codebase="" attribute (which also works in relative form , like codebase="./applets" or codebase="."), or jarring it up and using the archive="" attribute.

[url=http://www.cs.tut.fi/~jkorpela/HTML3.2/5.4.html]Here[/url] is another good primer that might help.

Best of luck.

kevjavaa at 2007-7-8 23:58:48 > top of Java-index,Java Essentials,New To Java...