• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet architecture

 
Venkata Seshaiah
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Currently I'm learning java, and have a general question I think is related to java architecture.
In java, it is said everything is an object. But in case of Applets( looks like also in servlets) we do not create any instance of Applet class we create. That means some how JVM is doing all this for us.
Also apart from environment variables there is lots of other info, fuctions which the JVM seems to be handling during the life of a applet.
There is mention of 'context' in the book I'm using, which I never really fully understood.
Can some one go into the details of how things work during the life cycle of an applet.
Similar info on Servlets also could be very rewarding.

thanks in advance
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you haven't seen The Sun Applet Tutorial?
 
Venkata Seshaiah
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK Tony,
Now I know that an instance of Applet class is created by the browser. To confirm this I conducted a small experiment, as follows.
import java.awt.*;
import java.applet.*;
public class Sample extends Applet
{
String age = null;
static int count =0; //static variable
public void init()
{
setBackground( Color.cyan);
setForeground(Color.black);
resize(500,500);
age = getParameter("age");
paramInfo = getParameterInfo();
count++; //incremented each time init() is //called
}
public void paint(Graphics g)
{
g.drawString("Hello Sample ", 50, 50);
g.drawString("paramage: " +age, 50,125);
g.drawString("count: " + count , 50, 155);
}
}

When the I opened the corresponding html file from IE with age set to 10, following are my observations,
1) count of 1 was displayed. and age = 10 was displayed.
2) I then changed the age to 20 in the html.
3) Pressed refresh on the browser. And what do I find?
I saw that the age was showing 20 and the count was showing 2.
If I refresh again the count increments to 3.
Does this mean that each time refresh is pressed a new instance of class is created. also the class is not reloaded again. Otherwise the count would not increase?
Is this browser specific behaviour. Or this is the expected behaviour as per Applet API?
Can anybody elaborate on what is going on behind the scenes.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic