Wednesday, 21 January 2015

How to run simple applet using command prompt

Applets are small application that are accessed on an internet server and run as a part of web document .The width and height statements specify the dimension of the display 
void drawString(String message,intx,inty) here message is the string output in java the upper right corner is location 0,0 .Pro Java Tricks is displayed at the position 200,200

KEY POINTS ON APPLET:

  • Applet do not need main class.
  • Applet must be read under appletviewer OR a Java-compatible browser.
  • Applet use interface provided by awt.

STEPS FOR CREATING AND RUNNING APPLET:

Following are the three simple steps to  create and run applet in command prompt

STEP #1:

paste this code in notepad file and save file name as firstapp.html choose the file type as all type and sve in it in the bin folder
<html>
<body>
<applet code="firstapp" width="300" height="300">
</applet>
</body>
</html>

STEP# 2:

paste the below code in notepad file and save file name as firstapp.java choose the file type as all type

import java.applet.*;
import java.awt.*;
public class firstapp extends Applet
{

public void paint(Graphics g){
g.drawString("Pro Java Tricks",200,200);
}

}

NOTE:

That class name and name in the html code should be same.

STEP #3:

compile the code by following command 

name of drive:\jdk\bin>javac firstapp.java
name of drive:\jdk\bin>appletviewer firstapp.html


OUTPUT:





No comments:

Post a Comment