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. Advertising

  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. Advertising

  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. Advertising

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. Steven J. Sobol

    Firefox not exiting (JApplet)

    Steven J. Sobol, Sep 5, 2006, in forum: Java
    Replies:
    4
    Views:
    462
    Steven J. Sobol
    Sep 6, 2006
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    917
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,031
    Smokey Grindel
    Dec 2, 2006
  4. Z
    Replies:
    12
    Views:
    4,988
    Knute Johnson
    Feb 19, 2007
  5. khadarnawas
    Replies:
    0
    Views:
    700
    khadarnawas
    Jul 20, 2007
Loading...

Share This Page