0% found this document useful (0 votes)
278 views

This Is Java Experiment

The document discusses creating applets in Java using two different methods - embedding an applet in an HTML file and using the appletviewer tool. It provides code examples of basic applets that display text, implement applet lifecycle methods, and use control loops. The examples demonstrate fundamental concepts for developing applets in Java.

Uploaded by

Nikam Arnav
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
278 views

This Is Java Experiment

The document discusses creating applets in Java using two different methods - embedding an applet in an HTML file and using the appletviewer tool. It provides code examples of basic applets that display text, implement applet lifecycle methods, and use control loops. The examples demonstrate fundamental concepts for developing applets in Java.

Uploaded by

Nikam Arnav
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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