Example : An applet program in java to display simple message using web browser (html file).
//(first of all create this java file)
import java.applet.Applet;  
import java.awt.Graphics;  
public class Emp extends Applet
{    
   public void paint(Graphics g)
   {  
     g.drawString("Welcome to Codershelpline",400,400);  
   }  
}  

//Save as file= Emp.java
//Compile as = javac Emp.java (Emp.class is created)
//No need to  interpret it as=java Emp.class	
------------------------------------------------------------------------------------
//(Now create this html file)
<html>  
<body>  
      <applet code="Emp.class" width="300" height="300"> </applet> 
      <!-- OR <applet code=Emp.class width=300 height=300> </applet> -- >  
</body>  
</html>

//Save as file=Emp1.html (finally save both the file in same directory/folder and then run this html file by simply double clicking it)
Example : An applet program in java to display a message in customize format using web browser (html file).
import java.applet.*;
import java.awt.*;
public class Emp extends Applet   
{
   public void paint(Graphics g)
   {
     Font f1=new Font ("Times New Roman",Font.BOLD,24);
     g.setFont(f1);
     setForeground(Color.green);
     setBackground(Color.blue);
     g.drawString("Codershelpline to all",250,250);
   }
}

//Save as file= Emp.java
//Compile as = javac Emp.java (Emp.class is created)
//Not interpret it as=java Emp	
---------------------------------------------------------------------------------------
<html>
<head>
   <title> Applet Program HTML Example </title>
</head>

<body>
   <applet code="Emp.class" height="65%" width="75%"></applet>
</body>
</html>

 //Save as file=Emp1.html (finally, run this applet program by simply double clicking it)
Example : An applet program in java to show its life-cycle using applet viewer.
import java.applet.*;
import java.awt.*;

/*<applet code="Emp.class" height="700" width="800"></applet>*/

public class Emp extends Applet
{
	String str= " CHL";
	public void init()
	{
		str=str+ "First step of life-cycle is executed";
	}
	public void start()
        {
		str=str+ "Second step of life-cycle is executed";
	}
	public void stop()
	{
		str=str+ "Third step of life-cycle is executed";
	}
	public void destroy()
	{ 
		str=str+ "Fourth step of life-cycle is executed";
	}
	public void paint(Graphics g)
	{
		Font f1=new Font("Calibri",Font.BOLD,24);
		setBackground(Color.green);
		g.setFont(f1);
        		g.drawString(str,250,350);
	}
}

//Save file as = Emp.java (in a folder or a drive)
//Compile as = javac Emp.java (No need to interpret)
//Run as = (write at any command prompt say C:\) appletviewer Emp.java  

 /*   -------------------------  OR  -------------------------------*/

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

public class Emp extends Applet
{
	String str= "CHL";
	public void init()
	{
		str=str+ "First step of life-cycle is executed";
	}
	public void start()
        {
		str=str+ "Second step of life-cycle is executed";
	}
	public void stop()
	{
		str=str+ "Third step of life-cycle is executed";
	}
	public void destroy()
	{ 
		str=str+ "Fourth step of life-cycle is executed";
	}
	public void paint(Graphics g)
	{
		Font f1=new Font("Calibri",Font.BOLD,24);
		setBackground(Color.green);
		g.setFont(f1);
        		g.drawString(str,250,350);
	}
    /*<applet code="Emp.class" height="700" width="800"></applet>*/
}

//Save file as = Emp.java (in a folder or a drive)
//Compile as = javac Emp.java (No need to interpret)
//Run as = (write at any command prompt say C:\) appletviewer Emp.java

 457 total views,  1 views today

Categories: Java

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.