How to create an Applet as a file.class ?

Javascript

How to create an Applet as a file.class ?


judy 08-02-2006, 8:27 PM

Hi, I am a WH4L user

I am new for java.. please help and teach me

am I right that I use like this ?

import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

I use text note to write a test.class
---------example--------------test.class---------------------------------------------
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class test extends Applet implements mouselistener
{
int x,y;
boolean clicked=false;
public void int()
{
this.addmouselistener(this);
}
public void mouseclicked(mouseevent e)
{
clicked=true;
x=e.getX();
y=e.getY();
update();
}
public void paint(graphics g)
{
if(clicked){
g.setcolor(color.pink);
g.filloval(x-20,y-20,40,40);
}
}
public void mouseentered(mouseevent e){}
public void mouseexited(mouseevent e){}
public void mousepressed(mouseevent e){}
public void mousereleased(mouseevent e){}
}
_________________________________________

-----my test.htm to run test.class-------
<applet
code="test.class"
width="204"
height="170"
</applet>
------------result I got------------
fail to load java applet

Please help me to fix my mistakes.
Thank you.

Best Regards,
Judy

 

Re: How to create an Applet as a file.class ?


cato 06-10-2008, 6:48 PM
Dear judy,did you put your class file and your htm file in the same directory?

Re: How to create an Applet as a file.class ?


treydx 06-14-2008, 8:11 AM
First of all, Java is extremely different from JavaScript, so that is probably why you aren't getting any responses.  Try a Java forum.

Next, did you really type all of that in "test.class"?  You've got to put your code in a file called "classname.java" and compile it into "classname.class".  You're going to have a bunch of jibberish in "test.class" and it shouldn't be readable.  It's been a while since I've done Java/Applets, so I'm assuming your code is copy/pasted from somewhere else and the syntax is correct...
webhost4life.com

Powered by Community Server, by Telligent Systems