HanneSThEGreaT
January 10th, 2008, 03:16 AM
Hello guys!
My applet code looks like this :
import java.awt.*;
public class Jet extends java.applet.Applet implements Runnable
{
Image jetpics[] = new Image[7];
String jetsrc[] = { "jet1.gif", "jet2.gif", "jet3.gif",
"jet4.gif", "jet5.gif", "jet6.gif", "jet7.gif" };
Image currentimg;
Thread runner = null;
int xpos, ypos, currx, curry;
int pauseDur = 100;
// initialize!
public void init()
{
// initialize jetpics array
MediaTracker mt = new MediaTracker(this);
for (int i=0; i < jetpics.length; i++) {
jetpics[i] = getImage(getCodeBase(), jetsrc[i]);
mt.addImage(jetpics[i], 0);
}
try {
mt.waitForID(0);
} catch (InterruptedException m) {
System.out.println("Image load interrupted");
}
// set screen background color
setBackground(Color.lightGray);
setLayout(new BorderLayout());
// add speed buttons
Panel p = new Panel();
p.setLayout(new FlowLayout());
p.add(new Button("Slower"));
p.add(new Button("Faster"));
add("South", p);
}
// process button clicks
public boolean action(Event evt, Object arg)
{
String buttonName = (String)arg;
if (buttonName.equals("Slower"))
{
pauseDur += 20;
if (pauseDur > 400)
pauseDur = 400; // slow limit = .40 seconds between frames
}
else if (buttonName.equals("Faster"))
{
pauseDur -= 20;
if (pauseDur < 20)
pauseDur = 1; // fast limit = .001 seconds between frames
}
return true;
}
// for thread
public void start()
{
if (runner == null)
{
runner = new Thread(this);
runner.start();
}
}
// for thread
public void stop()
{
if (runner != null)
{
runner.stop();
runner = null;
}
}
// fly
public void run()
{
while(true) // loop loop
{
// fly level from left edge to center
currentimg = jetpics[0];
jetfly(-50, 175 - 25, 6, 0, 30);
// loop - currx,curry corrections fine-tune jet's pivot
currentimg = jetpics[1];
jetfly(currx, curry, 5, -3, 12);
currentimg = jetpics[2];
jetfly(currx+5, curry-10, 1, -4, 12);
currentimg = jetpics[3];
jetfly(currx+20, curry-10, -2, -3, 12);
currentimg = jetpics[4];
jetfly(currx-10, curry, -5, 0, 16);
currentimg = jetpics[5];
jetfly(currx+5, curry, -3, 5, 12);
currentimg = jetpics[6];
jetfly(currx+5, curry-10, 3, 7, 13);
// fly level from center to right edge
currentimg = jetpics[0];
jetfly(currx, curry, 6, 0, 40);
} // end while()
} // end run()
// animate
void jetfly(int startx, int starty, int incx, int incy, int hops)
{
for (int i = 1; i <= hops; i++)
{
this.xpos = startx;
this.ypos = starty;
repaint();
pause(pauseDur);
startx += incx;
starty += incy;
}
currx = startx;
curry = starty;
}
// pause between animation frames - sets frames/second
void pause(int time)
{
try { Thread.sleep(time); }
catch(InterruptedException e) { }
}
// override paint()
public void paint(Graphics g)
{
if (currentimg != null)
g.drawImage(currentimg, xpos, ypos, this);
}
}
Right, when compiling it, I receive absolutely no errors at all, so, it's safe to assume that everything should be working fine, isn't it ¿
Now, I do this in my web page :
<HTML>
<HEAD>
<TITLE>Running a Java Applet in an HTML document</TITLE>
</HEAD>
<BODY BGCOLOR="white">
<!-- PAGE HEADING -->
<DIV ALIGN="center">
<IMG SRC="jetaway.gif" HEIGHT="138" WIDTH="195">
<BR>
<HR WIDTH="50%">
<BR>
<!-- APPLET -->
<APPLET CODE="Jet.class" HEIGHT="228" width="360">
<H1>if you see this message, your browser could not load the applet</H1><BR>
</APPLET>
<BR>
<HR>
<BR>
</DIV>
</BODY>
</HTML>
When I open this web page in IE , it tells me :
Load: Class Jet not found
Can anyone tell me what is wrong here ¿ Have I done something wrong, and what ¿
Any help would be greatly appreciated.
My applet code looks like this :
import java.awt.*;
public class Jet extends java.applet.Applet implements Runnable
{
Image jetpics[] = new Image[7];
String jetsrc[] = { "jet1.gif", "jet2.gif", "jet3.gif",
"jet4.gif", "jet5.gif", "jet6.gif", "jet7.gif" };
Image currentimg;
Thread runner = null;
int xpos, ypos, currx, curry;
int pauseDur = 100;
// initialize!
public void init()
{
// initialize jetpics array
MediaTracker mt = new MediaTracker(this);
for (int i=0; i < jetpics.length; i++) {
jetpics[i] = getImage(getCodeBase(), jetsrc[i]);
mt.addImage(jetpics[i], 0);
}
try {
mt.waitForID(0);
} catch (InterruptedException m) {
System.out.println("Image load interrupted");
}
// set screen background color
setBackground(Color.lightGray);
setLayout(new BorderLayout());
// add speed buttons
Panel p = new Panel();
p.setLayout(new FlowLayout());
p.add(new Button("Slower"));
p.add(new Button("Faster"));
add("South", p);
}
// process button clicks
public boolean action(Event evt, Object arg)
{
String buttonName = (String)arg;
if (buttonName.equals("Slower"))
{
pauseDur += 20;
if (pauseDur > 400)
pauseDur = 400; // slow limit = .40 seconds between frames
}
else if (buttonName.equals("Faster"))
{
pauseDur -= 20;
if (pauseDur < 20)
pauseDur = 1; // fast limit = .001 seconds between frames
}
return true;
}
// for thread
public void start()
{
if (runner == null)
{
runner = new Thread(this);
runner.start();
}
}
// for thread
public void stop()
{
if (runner != null)
{
runner.stop();
runner = null;
}
}
// fly
public void run()
{
while(true) // loop loop
{
// fly level from left edge to center
currentimg = jetpics[0];
jetfly(-50, 175 - 25, 6, 0, 30);
// loop - currx,curry corrections fine-tune jet's pivot
currentimg = jetpics[1];
jetfly(currx, curry, 5, -3, 12);
currentimg = jetpics[2];
jetfly(currx+5, curry-10, 1, -4, 12);
currentimg = jetpics[3];
jetfly(currx+20, curry-10, -2, -3, 12);
currentimg = jetpics[4];
jetfly(currx-10, curry, -5, 0, 16);
currentimg = jetpics[5];
jetfly(currx+5, curry, -3, 5, 12);
currentimg = jetpics[6];
jetfly(currx+5, curry-10, 3, 7, 13);
// fly level from center to right edge
currentimg = jetpics[0];
jetfly(currx, curry, 6, 0, 40);
} // end while()
} // end run()
// animate
void jetfly(int startx, int starty, int incx, int incy, int hops)
{
for (int i = 1; i <= hops; i++)
{
this.xpos = startx;
this.ypos = starty;
repaint();
pause(pauseDur);
startx += incx;
starty += incy;
}
currx = startx;
curry = starty;
}
// pause between animation frames - sets frames/second
void pause(int time)
{
try { Thread.sleep(time); }
catch(InterruptedException e) { }
}
// override paint()
public void paint(Graphics g)
{
if (currentimg != null)
g.drawImage(currentimg, xpos, ypos, this);
}
}
Right, when compiling it, I receive absolutely no errors at all, so, it's safe to assume that everything should be working fine, isn't it ¿
Now, I do this in my web page :
<HTML>
<HEAD>
<TITLE>Running a Java Applet in an HTML document</TITLE>
</HEAD>
<BODY BGCOLOR="white">
<!-- PAGE HEADING -->
<DIV ALIGN="center">
<IMG SRC="jetaway.gif" HEIGHT="138" WIDTH="195">
<BR>
<HR WIDTH="50%">
<BR>
<!-- APPLET -->
<APPLET CODE="Jet.class" HEIGHT="228" width="360">
<H1>if you see this message, your browser could not load the applet</H1><BR>
</APPLET>
<BR>
<HR>
<BR>
</DIV>
</BODY>
</HTML>
When I open this web page in IE , it tells me :
Load: Class Jet not found
Can anyone tell me what is wrong here ¿ Have I done something wrong, and what ¿
Any help would be greatly appreciated.