How to Create a Java Applet in Netbeans

Written by fred larrey
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Create a Java Applet in Netbeans
NetBeans helps you write your Java Code easily (computer image by blaine stiger from

Netbeans is an IDE for Java, PHP and Apache. IDE, which stands for Integrated Development Environment, is basically a fancy way of saying "editor." Using Netbeans, you can write Java code and run Java programs quickly and easily. This is in contrast to running your Java programs from the Terminal and writing them in Notepad, which can become tedious and can be quite complicated. If you do not have Netbeans, you can install it using the link in the Resources section below.

Skill level:

Other People Are Reading


  1. 1

    In Netbeans, create a new project by going to "File > New Project." In the "Choose Project" window, click "Java Application" and click "Next." Name the project "FirstApplet" and click "Finish."

  2. 2

    Under "Source Packages" double-click the "firstapplet" package (with the brown box icon) and click "New > Java Class." Name the class "GreenLines" and click "Finish."

  3. 3

    Under the line "package firstapplet;" type the following two lines of Java code:

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

    This imports the Applet and Graphics Java libraries, which you will use in your code.

  4. 4

    Between "public class GreenLines" and the "{" type "extends Applet" to tell Java that the GreenLines class is going to be an Applet.

  5. 5

    Inside the GreenLines class, initialise the height and width variables for your applet by typing the line:

    int m_height, m_width;

  6. 6

    Create the following two methods ("init" and "paint) to have your Java code initialise the Applet with a height, width and background colour, then "paint" 10 lines across the screen:

    public void paint(Graphics m) { m.setColor(; for (int i = 0; i < 10; ++i) m.drawLine(m_width, m_height, i * m_width / 10, 0); } public void init() { m_width = get Size().width; m_height = get Size().height; set Background(; }

  7. 7

    Click "Run" from the top menu of Netbeans, then click "Run File." Your Java Applet's window will pop up and you will see 10 lines drawn across the screen.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.