Applet Class _ init(), Start(), Stop(), Destroy(), paint()

Discussion in 'Java' started by Vasu, Jan 21, 2009.

  1. Vasu

    Vasu Guest

    Hi !

    I'm a newbie in Java programming. Anybody there who can clear my
    confusion regarding Applet class.

    As per my understanding, when we create an applet the subject line
    four methods are must to be there to run the applet. Whereas I've seen
    the applet which are coded with even one of the above methods i.e.
    sometime with only Start(), or sometime with only paint() method. How
    does it work with one only method when all four methods are required.
    Example following two applet codes :

    (1)

    //With only paint method (to draw a line)

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

    public class LineDrawTest extends Applet{
    int x=300,y=100,r=50;

    public void paint(Graphics g){
    g.drawLine(3,300,200,10);
    g.drawString("Line",100,100);

    }
    }


    (2)

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

    public class ListBoxExample extends Applet
    {
    Image img;
    public void init()
    {
    Frame frame = new Frame("My Frame With List Box");
    frame.setSize(300,400);
    img=getImage(getDocumentBase(),"SriHanumanJi.jpg");
    List list=new List(3, true);
    list.add("Option 1");
    list.add("Option 2");
    list.add("Option 3");
    Panel panel=new Panel();
    panel.setSize(50,50);
    panel.add(list);
    frame.add(panel);
    frame.setVisible(true);
    }
    public void paint(Graphics gr)
    {
    gr.drawImage(img,0,0,this);
    }
    }

    Now, you can see while, the first code is just with the use paint()
    method i.e. no use of init() and start() method so how can that start
    when there is no init() / start() methods available. Similarly in the
    second code, there is no Start() / Stop() / Destroy() methods, so how
    is it started with having Start() method.

    Kindly clear my confusion so that I can proceed further.
    Thanks in advance.
    Vasu
    Vasu, Jan 21, 2009
    #1
    1. Advertising

  2. Vasu

    Mark Space Guest

    Vasu wrote:

    > As per my understanding, when we create an applet the subject line
    > four methods are must to be there to run the applet. Whereas I've seen
    > the applet which are coded with even one of the above methods i.e.
    > sometime with only Start(), or sometime with only paint() method. How
    > does it work with one only method when all four methods are required.
    > Example following two applet codes :
    >
    > (1)
    >
    > //With only paint method (to draw a line)
    >
    > import java.applet.*;
    > import java.awt.*;
    >
    > public class LineDrawTest extends Applet{


    "extends Applet"

    Check the Applet class, it has the methods you are missing.

    <http://java.sun.com/javase/6/docs/api/java/applet/Applet.html>

    This is basic Java inheritance, you should study up on it if you are
    going to program in Java.
    Mark Space, Jan 21, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. troy makaro
    Replies:
    8
    Views:
    759
    Andrew Thompson
    Oct 8, 2005
  2. Replies:
    4
    Views:
    4,626
    Brendan Guild
    Oct 23, 2005
  3. VisionSet
    Replies:
    3
    Views:
    505
    VisionSet
    Jun 27, 2006
  4. Replies:
    0
    Views:
    557
  5. Ook
    Replies:
    2
    Views:
    323
Loading...

Share This Page