Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Why does JApplet not need an instance? (http://www.velocityreviews.com/forums/t136530-why-does-japplet-not-need-an-instance.html)

Jenny 09-01-2004 03:50 AM

Why does JApplet not need an instance?
 
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);
}
}

Liz 09-01-2004 04:11 AM

Re: Why does JApplet not need an instance?
 

"Jenny" <jenny_jones_79@hotmail.com> wrote in message
news:88d928c2.0408311950.472ce2e8@posting.google.c om...
> 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.



Johan Poppe 09-01-2004 05:22 PM

Re: Why does JApplet not need an instance?
 
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'.)

--
Riktig sitering gjør meldingene dine lettere å lese:
< url: http://home.online.no/~vidaandr/news/OBSquoting.html >


All times are GMT. The time now is 02:52 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.