1

I am a novice in java programming.This is my applet code for SimpleApplet.java:

import java.awt.*;
import java.applet.*;
/*
<applet code="SimpleApplet" width=200 height=60>
</applet>
*/
public class SimpleApplet extends Applet
{
public void paint(Graphics g)
{
 g.drawString("A simple Applet",20,20);
}
}

I first compiled it in command prompt by javac SimpleApplet.java and then used java SimpleApplet. It throws up error that main class is not found in class SimpleApplet,please define main method. Where am I wrong here ?

Konstantin Yovkov
  • 62,134
  • 8
  • 100
  • 147
shri_wahal
  • 344
  • 1
  • 4
  • 16

1 Answers1

1
javac SimpleApplet.java 

and then used

java SimpleApplet

Do instead:

javac SimpleApplet.java 
appletviewer SimpleApplet.java 

The trick here is that the applet viewer will read the source, and use the applet element defined in the comment to make an 'applet HTML' to run it.

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    The approach is also demonstrated in answers seen [here](http://stackoverflow.com/q/7454656/230513). – trashgod Oct 12 '14 at 04:11