This Is Java Experiment

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

 

//Create two applets by using different ways in java.

// By Java-enabled web browser tool  (Adding applet in HTML file)myapplet.java


 
import java.applet.*;
import java.awt.*;
 public class myapplet extends Applet
  {
    public void paint(Graphics g)
    {    
        g.drawString(" Welcome Students to our applet code",200,100);
    }
 }    
//   first.html  
 <html>
<body>
<applet   code="myapplet.class"   width=400   height=500>  </applet>  
 </html>
 </body>
 
Output:
                   
//By Java appletviewer tool (Adding /Embedding applet code in Java)
 
import java.applet.*;
import java.awt.*;
 
/* <applet   code="myapplet.class"   width=400   height=500>     </applet> */
 public class myapplet extends Applet
 {
 public void paint(Graphics g)
 {    
        g.drawString("Welcome Students to our applet code",200,100);
 }
 }
 
 
Output:
Welcome Students to our applet code

1> Develop basic applet to display “Welcome to the World of Applet”.


import java.applet.*; import java.awt.*;
 
/* <applet   code="myapplet.class"   width=400   height=500>
    </applet> */   public class myapplet extends Applet
  {
      public void paint(Graphics g)
      {    
           g.drawString("Welcome to the World of Applet ",200,100);
       }
          }
Output:
     Welcome to the World of Applet

//2>Develop program to implement all methods of applet.


import java.applet.*; import java.awt.*;
 
/* <applet   code="myapplet.class"   width=400   height=500>
     </applet> */ public class myapplet extends Applet
{    public void init()
   {
  System.out.println("I am in init method");
   }
   public void start()
   {
  System.out.println("I am in start method");
   }
   public void stop()
   {
  System.out.println("I am in stop method");
   }
   public void destory()
   {
  System.out.println("I am in destory method");
   }
   public void paint(Graphics g)
   {
  g.drawString("Welcome",50,100);
   }
}
 

//3>Develop a program using control loops in applets.


 
import java.applet.*; import java.awt.*;
/*<applet  code="control.class"   width=400   height=500>
  </applet> */
public class control extends Applet
{
 public void paint(Graphics g)
   {    
     int i,x=100,y=50;
     for(i=1;i<=10;i++)
        {
            g.drawString(" "+i,x,y);  
                   
            y=y+20;
        }
    }
}
/*
Output:
1
2
3
4
5
6
7
8
9
10
*/

You might also like