Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Why does JApplet not need an instance?

Reply
Thread Tools

Why does JApplet not need an instance?

 
 
Jenny
Guest
Posts: n/a
 
      09-01-2004
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);
}
}
 
Reply With Quote
 
 
 
 
Liz
Guest
Posts: n/a
 
      09-01-2004

"Jenny" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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.


 
Reply With Quote
 
 
 
 
Johan Poppe
Guest
Posts: n/a
 
      09-01-2004
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 >
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Swing Components are not visible in japplet khadarnawas Java 0 07-20-2007 06:23 AM
Why doesn't my JApplet repaint itself automatically? Z Java 12 02-19-2007 12:00 AM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Firefox not exiting (JApplet) Steven J. Sobol Java 4 09-06-2006 06:49 PM



Advertisments