urbaindepuce
urbaindepuce

Reputation: 523

Debug/Run Applet in NetBeans

How can I debug or run a class that extends java.applet.Applet? I am able to run the applet from the command line with appletviewer.

appletviewer runapp.html

Here is what class looks like:

import java.awt.Graphics;
import java.applet.Applet;

public class FancyApplet extends Applet {
    @Override
    public void paint(Graphics g) {
        g.drawString("Hello World!", 20, 20);
    }
}

Here is what the HTML file looks like

<!doctype html>

<head>
    <meta charset="utf-8">
    <title>A Fancy Applet</title>
</head>

<object type="application/java" width="200" height="300">
    <param name="code" value="FancyApplet.class">
</object>

How do I have to organize those files within my project and what settings do I have to use to debug the Applet in NetBeans? The thread Running a java applet from netbeans? did not help unfortunately. I did what was suggested, but get a message telling me that the main class was not found. What I took from it though was that in my case the HTML file is not even needed? But just because I am curious is it still possible or recommended to use it?

Upvotes: 2

Views: 1963

Answers (1)

Am_I_Helpful
Am_I_Helpful

Reputation: 19168

As you don't have public static void main(String[] args) in your FancyApplet class, so the above error is produced.

You can run your java applet in the NetBeans IDE by pressing Shift + F6 key from your main class(keeping cursor inside FancyApplet class here). It'll run the applet program without searching for the main method.

This is an alternate shortcut method of running individual classes in NetBeans IDE.

Upvotes: 2

Related Questions