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

V

Vasu

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
 
M

Mark Space

Vasu said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top