Why does JApplet not need an instance?

Discussion in 'Java' started by Jenny, Sep 1, 2004.

  1. Jenny

    Jenny Guest

    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);
    }
    }
     
    Jenny, Sep 1, 2004
    #1
    1. Advertisements

  2. Jenny

    Liz Guest

    "Jenny" <> wrote in message
    news:...
    > 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.
     
    Liz, Sep 1, 2004
    #2
    1. Advertisements

  3. Jenny

    Johan Poppe Guest

    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 >
     
    Johan Poppe, Sep 1, 2004
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Horace Nunley

    why why why does function not work

    Horace Nunley, Sep 27, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    710
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Sep 27, 2006
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    1,362
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,819
    Smokey Grindel
    Dec 2, 2006
  4. Z
    Replies:
    12
    Views:
    5,410
    Knute Johnson
    Feb 19, 2007
  5. Skybuck Flying
    Replies:
    16
    Views:
    926
    tragomaskhalos
    Aug 25, 2007
  6. anne001
    Replies:
    4
    Views:
    191
  7. Lionel MAIAUX
    Replies:
    1
    Views:
    148
    Hidetoshi NAGAI
    Sep 5, 2006
  8. Greg Hauptmann
    Replies:
    9
    Views:
    487
    Loren Segal
    Jun 16, 2008
Loading...