Reputation: 848
I have searched for the past few days for a solution to this problem and I am beating my head against the wall. I'm knew to programming in java so bear with me.
I am currently trying to implement a Java Applet into an HTML page of mine for a school project. The Applet runs fine in Eclipse using AppletViewer, as well as in the web browser in a program called Blue Jay. I have exported the program into a jar file in the same directory as my HTML page, and added the necessary code to my HTML file, but whenever I actually run the HTML file the Applet gives me an "Illegal Argument Exception: name" error. The details of the error include the phrase "java.net.MalformedURLException:unknown protocol:e."
This is the relevant code for my HTML file:
<applet code="MovingBoxes.class" archive="E:\WebSystems\WebPages\Animations.jar"
width="350" height="350" >Animation of moving boxes</applet>
When the error occurs the phrase inside of the applet tags is not displayed either if that is significant. I have tried exporting other applets to see if they work and have received the same error every time. I'm also fairly certain that the destination for the file is correct, because when I change the destination name to something incorrect a "Class Not Found" error occurs instead.
And in the off chance that the error is in my applet, here is my applet code.
package theBig;
import java.awt.*;
public class MovingBoxes extends java.applet.Applet implements Runnable
{
Thread runner;
int size = 15;
int x_value = 200;
int y_value = 175;
int rndm_x;
int rndm_y;
int move = 1;
int cntr = 0;
Image dbImage;
Graphics dbg;
int x_value2 = 240;
int y_value2 = 250;
int rndm_x2;
int rndm_y2;
public void start()
{
if (runner == null) {
runner = new Thread(this);
runner.start();
}
}
public void stop()
{
if (runner != null) {
runner.stop();
runner = null;
}
}
public void run()
{
setBackground(Color.white);
while (true) {
rndm_x = (int)(Math.random()*10+1);
rndm_y = (int)(Math.random()*10+1);
if (rndm_x > 5)
x_value += move;
else
x_value -= move;
if (rndm_y > 5)
y_value = 50;
else
y_value = 50;
rndm_x2 = (int)(Math.random()*10+1);
rndm_y2 = (int)(Math.random()*10+1);
if (rndm_x2 > 5)
x_value2 += move;
else
x_value2 -= move;
if (rndm_y2 > 5)
y_value2 = 50;
else
y_value2 = 50;
if (x_value + size > x_value2)
{
cntr = 50;
}
while(cntr > 0)
{
cntr --;
x_value --;
x_value2 ++;
repaint();
try { Thread.sleep(25); }
catch (InterruptedException e) { }
}
repaint();
try { Thread.sleep(25); }
catch (InterruptedException e) { }
}
}
public void update(Graphics g) {
dbImage = createImage(getWidth(),getHeight());
dbg = dbImage.getGraphics();
paint(dbg);
g.drawImage(dbImage,0,0,this);
}
public void paint(Graphics g) {
g.setColor(Color.red);
g.drawRect(x_value, y_value, size, size);
g.fillRect(x_value, y_value, size, size);
g.setColor(Color.blue);
g.drawRect(x_value2, y_value2, size, size);
g.fillRect(x_value2, y_value2, size, size);
}
} `
Like I said, I have searched everywhere for an answer and come up empty handed. Any help you can offer me is greatly appreciated.
Upvotes: 0
Views: 1054
Reputation: 2826
Maybe its a typo but you are missing a " after .jar in your HTML code.
If that doesn't help, maybe your archive should be a URL, not just a file path. Can you try this:
<applet code="MovingBoxes.class" archive="file:/E:/WebSystems/WebPages/Animations.jar"
width="350" height="350" >Animation of moving boxes</applet>
Upvotes: 1