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
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