1

I have an applet that was originally built with JBuilder long time ago. I believe it worked fine until fairly recently. It has stopped working. I have imported it to Eclipse to debug, and found that public static void main() is not called. This can explain the applet's crash.

My hunch is that the newer JVM does not call public static void main() for applets. Could anyone shed some light on this?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Hong
  • 17,643
  • 21
  • 81
  • 142

3 Answers3

2

Java Applets require the applet lifecycle. There isn't any main for an applet.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Lews Therin
  • 10,907
  • 4
  • 48
  • 72
  • 1
    This means what we had in the old days - An Applet and Application - is not available anymore. http://www.heatonresearch.com/articles/18/page6.html – Hong Sep 16 '12 at 14:49
  • 1
    Wow, I didn't know that. But AFAIK, it doesn't require one because the browsers can call an applet method, meaning main doesn't have to be the entry point. So if you press click on a new tab and go back to the tab with the applet, the applet calls start() and not init() (or main as it was) – Lews Therin Sep 16 '12 at 14:53
  • 1
    *"what we had in the old days - An Applet and Application - is not available anymore."* Rubbish. It is called an hybrid, and is alive and well. Ask on a separate question if you would like clarification. – Andrew Thompson Sep 16 '12 at 18:53
  • @AndrewThompson Can you explain here or add some links? I would like to know as well. Thanks – Lews Therin Sep 16 '12 at 18:59
  • @AndrewThompson I will ask now. – Lews Therin Sep 16 '12 at 19:11
1

The main() method is normally used for applications. Any calls that you need to make at initialisation time should really be placed in:

public void init()

in your applet.

Reimeus
  • 158,255
  • 15
  • 216
  • 276
1

My hunch is that the newer JVM does not call public static void main() for applets. Could anyone shed some light on this?

To my knowledge dating back to 1997, no VM has ever called main() for applets.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • I think you are right. main() was created for the applet in case it is run as an application. I thought it was called because I noticed some initialization code (not automatically generated) in main. I have fixed the problem by importing the JBuilder project into Eclipse, replacing Applet with JApplet, and making a few other changes. I am not sure which step fixed the problem. – Hong Sep 17 '12 at 11:00