Friday, November 18, 2011


Create New Project

  1. Click menu File - New Project...

  2. In Categories choose Java, in Projects choose Java Desktop Application, click Next button.

  3. In Disclaimer dialog, click Next button.

  4. Set Project Name = Project01. To determine your own location, click Browse..., click Finish.

  5. In Projects tab, we can see a new project named Project01.
    In project01 package, there are 3 classes that created automatically,,, and But for this section, we should ignore them.

Add New Frame

  1. First, add new package by right click Source Packages, choose New - Java Package...

  2. Set Package Name = package01, click Finish button.

    In Projects tab has added package01 packages.

  3. Right click package01 package, choose New - JFrame Form...

    If there isn't JFrame Form... submenu, choose Other...

    In Categories choose Swing GUI Forms, In File Types choose JFrame Form.

  4.  Set Class Name = Frame01.

Add Component to Frame

In this case, we will add JButton control.

  1. Add JPanel container.

    In Palette tab, Swing Containers subtab, click Panel container (not drag), then put panel by clicked frame, and set the measurement.

  2. Change panel's layout by right click its panel, choose Set Layout - Null Layout. Null Layout give ability to positioning/measuring a control independently.

  3. In Palette tab, Swing Controls subtab, click Button control (not drag), then put it by clicked panel, and set the measure.

Assigning the Control

Now assign a command, when the button was clicked.
  1. Right click jButton1, choose Events - Action - actionPerformed.

  2. Insert following command in jButton1ActionPerformed :
    JOptionPane.showMessageDialog(null, "Hello Netbeans.");
    notice the case-sensitive.

  3. But there is an error symbol. To solve it, click that symbol and choose Add import for javax.swing.JOptionPane.

  4. When run program directly, it will be showed by loading To showing file:
    right click Project01 node, choose Properties...

  5. In Categories choose Run, then browse... Main Class file.

  6. Choose, click Select Main Class.

  7. Run a program by hit F6, or the following toolbar:

  8. The Frame would be showed after click jButton1.

  9. To change Look & Feel, right click Project01 node, choose Properties (like as 4th step), in Categories choose Application -> Desktop App, at Look & Feel choose javax.swing.plaf.metal.MetalLookAndFeel. Click OK button.

We have created it.