Reputation: 384
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 ?
Upvotes: 2
Views: 1417
Reputation: 168845
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.
Upvotes: 2