Applet Methods

JApplet is a class that represents the Swing Applet. It is a subclass of Applet class and must extended by   all the applets that use Swing.

 

Methods......

Init()---called once in an applet, called when applet is first loaded.

Start()---called at least once,when applet is started,called after init() method

Stop()---called at least once, when the browser leaves the web page.

Destroy()---called once when the browser unloads the applet(final clean-up)

Paint()---used if u want to do any drawing or painting like drawLine,setColor etc.

//EXAMPLE

import javax.swing.*;

import java.awt.*;

public class appletmeathod extends JApplet

{

                int iniit = 0;

                int staart = 0;

                int stoop = 0;

                int destrooy = 0;

               

                public void init()

                {

                                iniit++;

                                repaint();

                }

                public void start()

                {

                                staart++;

                                repaint();

                }

                public void stop()

                {

                                stoop++;

                                repaint();

                }

               

                public void destroy()

                {

                                destrooy++;

                                repaint();

                }

                public void paint(Graphics grp)

                {

                        grp.drawString("init has been invoked "+ String.valueOf(iniit) + "times",20,20);

                        grp.drawString("start has been invoked "+ String.valueOf(staart) + "times",20,35);

                        grp.drawString("stop has been invoked "+ String.valueOf(stoop) + "times",20,50);

                        grp.drawString("destroy has been invoked "+ String.valueOf(destrooy) +"times", 20,65);

                }

}

/*

<applet code ="appletmeathod.class" height =400 width=400>

</applet>

*/

Applet Methods

//SECOND EXAMPLE

import java.applet.*;

public class hello extends Applet

 {

    public void paint(Graphics graf)

      {

Dimension dim=getSize();

graf.setColor(Color.BLACK);

graf.fillRect(0,0,dim.width,dim.height);

graf.setFont(new Font("San-seriff",Font.BOLD,24));

graf.setColor(new Color(255,215,0));

graf.drawString("Xcnotes.com!",60,40);

graf.drawImage(getImage(getCodeBase(),"cou.jpg"),20,60,this);

          }

     }

/*<applet code="hello.class" height=300 width=740></applet*/

Applet