Why does JApplet not need an instance?

J

Jenny

Hi,

In an Applet program, it does not have an instance. Could you tell me
why? Thanks a lot.

Below is a sample:

import java.awt.*;

public class SalutonApplet extends javax.swing.JApplet {
String greeting;

public void init() {
greeting = "Saluton mondo!";
}

public void paint(Graphics screen) {
Graphics2D screen2D = (Graphics2D)screen;
screen2D.drawString(greeting, 25, 50);
}
}
 
L

Liz

Jenny said:
Hi,

In an Applet program, it does not have an instance. Could you tell me
why? Thanks a lot.

Below is a sample:

import java.awt.*;

public class SalutonApplet extends javax.swing.JApplet {
String greeting;

public void init() {
greeting = "Saluton mondo!";
}

public void paint(Graphics screen) {
Graphics2D screen2D = (Graphics2D)screen;
screen2D.drawString(greeting, 25, 50);
}
}

browser does it I think.
 
J

Johan Poppe

Jenny skrev:
In an Applet program, it does not have an instance. Could you tell me
why? Thanks a lot.

(Sample snipped)

Yes, you have an instance of the SalutonApplet class here.

Notice that neither init() nor paint() are static methods. You newer
call "new SalutonApplet()", but the appletrunner calls it before
calling init(). You also don't have an explicit reference to that
instance, but the appletrunner keeps one. (And you have 'this'.)
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top