To run a Java Applet using command prompt, we need to create a html file and link it to our applet.
To do so, follow these steps:
- Write your java applet code in a text editor and save it as YourClassName.java (eg. MyAppet.java for this program)
- Write the following html code in a text editor, replace the YourClassName.class with the name of your class and save it as YourClassName.html (eg. MyApplet.html for this program)
XHTML1234567<html><head><title>My Applet</title></head><Applet Code = "YourClassName.class" width="500" height="450"></Applet></html>
Play around with the ‘width‘ and ‘height‘ attributes in the program to resize your applet.
- Make sure u save the applet file and the html file in the same folder.
- Then compile your applet in the command prompt (i.e. till ‘javac ClassName.java’) but don’t run it.
If you don’t know how to do that then follow this post till step 7. Skip the steps that u know you have already done.
- Then type ‘appletviewer YourClassName.html’
- And Voila! Your applets running!
Now start practicing applets and let us know how it works for you
Lalit is a technology enthusiast, a programming lover and currently an Android fan.
Latest posts by Lalit Mali (see all)
- Rank Pages in a Directory by Occurrence of a Particular Word in them – Java Data Mining - October 16, 2012
- Java Data Mining: Number of occurrences of a word in a file - October 15, 2012
- Calculate factorial of a number using C++ Recursive function - October 14, 2012