View Full Version : Running an Applet in Netbeans

July 28th, 2008, 04:14 AM

I'm trying to run a Java applet in Netbeans. All the sources I can find say that you simply right click the file and choose "Run File" from the pop-up menu, but when I do this I get an error that says "Class [class name] does not have a main method".


July 28th, 2008, 04:53 AM
I just created an empty Applet in NetBeans right clicked it > "Run File" and it worked. NetBeans detected that the class extends "JApplet", does yours extend JApplet?

Maybe you could do a "Clean and Build" on your project to try and get it to refresh

Failing this perhaps you could post your code...

July 28th, 2008, 05:57 AM
Thanks for your reply :-)

I tried creating a new project with a new applet, copied the old code in, and it ran, oddly enough. Not sure why it didn't run the original. It still won't. Here's the code for reference:

package miscellaneous;

import javax.swing.*;
import java.awt.*;

* @author ceclauson
class FocusTester extends JApplet {

public void init() {
this.setLayout(new FlowLayout());
JTextField tf1 = new JTextField();
JTextField tf2 = new JTextField();
JTextField tf3 = new JTextField();



I'm pretty happy with this, but I still have no idea why it won't run the original.

Thanks again,

July 28th, 2008, 07:20 AM

What was the original project type? "Java Class Library" or "Java Application"?

What version of NetBeans?

July 28th, 2008, 08:39 AM
The project type is "Java Application," but I created two new projects, one a Java application and the other a Class Library, and in both I was able to create and run a working applet.

My Netbeans version is 6.1.

November 16th, 2009, 09:48 PM
The class FocusTester needs to be public. Then NetBeans will run it as an applet.