// JP opened flex table

Click to See Complete Forum and Search --> : Strange Applet!


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.

KrisSimonis
January 10th, 2008, 03:34 AM
Where did you put the Jet.Class? the Applet URL needs to point properly to it, the way you wrote it, it has to be in the same directory as the HTML.
I checked the tag at W3Schools (http://www.w3schools.com/tags/tag_applet.asp), maybe you also need the codebase thingamajig?

Also, the APPLET tag has been deprecated, so not all browsers might support it.

HanneSThEGreaT
January 10th, 2008, 04:40 AM
Hi Thanx for responding!
Yeah, the Jet.Class is in the same directory.

I don't think I have to include the CODEBASE, if I have to, can anyone tell me what then.

I'm just working out an example on how to use a Java applet with HTML, and we mainly use Internet Explorer here.

I don't know - I honestly thought this applet would work, maybe I should try a less complicated applet to be used as an example, if I cannot get this fixed.

What do you think ¿
PS, I'm not a pro with JAVA, but, I have to make an example for my web design students about this.

dlorde
January 10th, 2008, 10:11 AM
Works for me here - with Jet.html in the same directory as Jet.class, IE and Maxthon browsers both load it and run it.

... maybe I should try a less complicated applet to be used as an example, if I cannot get this fixed.If the applet class can't be found, how will making it less complicated help?

I am always doing that which I cannot do, in order that I may learn how to do it...
P. Picasso

HanneSThEGreaT
January 11th, 2008, 12:53 AM
Thanx for the confirmation dlorde! :thumb:

Could it be a setting on my browser then, because I tried it now again, and still the "Load Class Jet not found" error appears. ¿

KrisSimonis
January 11th, 2008, 09:11 AM
Maybe you misconfigured something in your IIS?

//JP added flex table