i am not able to execute applets. i have written the following program.

import java.awt.*;
import java.applet.*;

/*
<applet code="sampleapplet" width=200 height=60>
</applet>
*/
public class sampleapplet extends Applet
{

public void paint(Graphics g)
{
g.drawString("simple applet",30,30);
}

} :?:

javac sampleapplet.java

appletviewer sampleapplet

The following error is displayed:
I/O exception while reading:e:\582\sampleapplet ( system cannot find the specified path.

note: location specified javafile is E:\582

Would be that because you have wrong idea about applet structure????

Read and learn

Did u try it out in a browser?

Did u try it out in a browser?

That thing would not even compile as it is missing MUST HAVE IT section. Therefore no point to discus browser deployment or Applet Viewer

No. i dont know how to execute in the browser. please help me.

The class name should be capital.

when the html code is wrriten in the java code then the compliation and excetion will be (as you did but the class name should be capital (Sampleapplet) )

javac Sampleapplet.java

appletviewer Sampleapplet.java


The applet window will be opened.

2. And the other if the html code is written in other file and save it has the same filename as the java filename or the other filename .html but when you are executing the you should give the correct filename by which you have saved.


javac Sampleapplet.java

appletviewer Sampleapplet.html (or)

appletviewer filename.html // if you have given the other filename

now the applet window will be opened.


Try it.

thanks....it worked.
why that first letter to be capital.

The first latter of class name is should be capital letter is not mandatory. its java naming rules. u can create the class name should be starting with small letter. in ur program is all normal java programs first we compile and run the programs using javac and java keywords.

but in applet u compile the program using javac and run the applet using appletviewer. if u want run the appletviewer u want write the applet tag in ur java program or separate file. if u write the <applet> </applet> with in the java file means u mention that file name fully with extension because the appletviewer read ur applet tag from that file only.

so only u get error. but in normal program java VM execute ur class file directly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.