java.lang.NoClassDefFoundError: PetePanel
PetePanel is defined in the code below!! By the way I run the applet
in a microsoft browser <applet code="PeteApplet.class" height=150
width=345> </applet>
All the GIF files called by the applet are available. Thanks a bunch
for your help.
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class PeteApplet extends JApplet {
PetePanel pete = new PetePanel();
public void init() {
JPanel pane = new JPanel();
pane.setLayout(new GridLayout(1, 1, 15, 15));
pane.add(pete);
setContentPane(pane);
}
}
class PetePanel extends JPanel implements Runnable {
Thread runner;
Image petePics[] = new Image[6];
Image back;
int current = 0;
int x = -10;
int y = 30;
PetePanel() {
super();
setBackground(Color.black);
String peteSrc[] = { "right1.gif", "right2.gif",
"right3.gif", "stop.gif", "blink.gif",
"wave.gif" };
Toolkit kit = Toolkit.getDefaultToolkit();
for (int i=0; i < petePics.length; i++) {
petePics = kit.getImage(peteSrc);
}
back = kit.getImage("backdrop.gif");
if (runner == null) {
runner = new Thread(this);
runner.start();
}
}
public void paintComponent(Graphics comp) {
Graphics2D comp2D = (Graphics2D)comp;
if (back != null)
comp2D.drawImage(back, 0, 0, this);
comp2D.setColor(Color.black);
comp2D.fillRect(0, 30, 450, 30);
if (petePics[current] != null)
comp2D.drawImage(petePics[current], x, y, this);
}
public void run() {
while (true) {
walk(-10, 275);
look();
blink(3);
wave(4);
walk(x, getSize().width + 10);
pause(1500);
}
}
public void walk(int start, int end) {
int showpic = 0;
for (int i = start; i < end; i += 5) {
x = i;
// swap images
current = showpic;
repaint();
pause(150);
showpic++;
if (showpic > 2)
showpic = 0;
}
}
public void blink(int numtimes) {
for (int i = numtimes; i > 0; i--) {
current = 4;
repaint();
pause(200);
current = 3;
repaint();
pause(1000);
}
}
public void wave(int numtimes) {
for (int i = numtimes; i > 0; i--) {
current = 3;
repaint();
pause(600);
current = 5;
repaint();
pause(1100);
}
}
public void look() {
current = 3;
repaint();
pause(1000);
}
public void pause(int time) {
try {
Thread.sleep(time);
} catch (InterruptedException e) { }
}
}
What about PetePanel.class? Is it available? That's what's being
complained about... not the GIF files.
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Sorry, but no you're wrong.
When you compile PeteApplet.java, it should produce both
PeteApplet.class and PetePanel.class. You need both of them to run the
applet. Not sure where you got the idea it would be otherwise, or why
you didn't get both classes... but that's the way it should be.
So, again, the problem is that you're missing PetePanel.class. It won't
do any good to rename PeteApplet.class to that; you need the real
PetePanel.class that's produced by javac.
java.security.AccessControlException: access denied
(java.io.FilePermission right1.gif read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:270)
at java.security.AccessController.checkPermission(AccessController.java:401)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)
at java.lang.SecurityManager.checkRead(SecurityManager.java:887)
at sun.awt.SunToolkit.getImageFromHash(SunToolkit.java:486)
at sun.awt.SunToolkit.getImage(SunToolkit.java:500)
at PetePanel.<init>(PeteApplet.java:32)
at PeteApplet.<init>(PeteApplet.java:6)
I checked to make sure that the GIF files have read-write permissions
to everyone (chmod 777). Your kind help is appreciated.
Regards
Murthy