Blog Archives

How to Create a new Java Applet in Netbeans

First create a new project. Make sure you select “Java Application” not Desktop Application or other types.

On the left hand of the screen you should see “Source Packages” and your project name in lower case underneath. If you don’t see this in the little window on the left, expand the coffee icon with your project name.

20121130_java_01

Right click your package (mine is javafileuploader in the screenshot above) and select New->Java Class.

Make sure your new class is selected, and then referencing my code snippet below, import java.applet.* and java.awt.* then add new functions for “paint” and “init”.

(code snippet courtesy of ehow link in references)

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javafileuploader;

import java.applet.*;
import java.awt.*;

/**
 *
 * @author fedora
 */
public class NewClass extends Applet {
int m_height, m_width;

public void paint(Graphics m) {
m.setColor(Color.black);
for (int i=0; i<10; ++i)m.drawLine(m_width,m_height,i*m_width/10,0);
}

public void init() {
    m_width=getSize().width;
    m_height=getSize().height;
    setBackground(Color.green);
}
}

Once you have this typed/pasted in, select run->file and voila! you should see a little applet window appear with a green background and oblique lines. You’re now ready to begin. Enjoy!
20121130_java_02

References
ehow.comhttp://www.ehow.com/how_6210608_create-java-applet-netbeans.html