- Click menu File - New Project...
- In Categories choose Java, in Projects choose Java Desktop Application, click Next button.
- In Disclaimer dialog, click Next button.
- Set Project Name = Project01. To determine your own location, click Browse..., click Finish.
- In Projects tab, we can see a new project named Project01.
In project01 package, there are 3 classes that created automatically, Project01AboutBox.java, Project01App.java, and
Project01View.java. But for this section, we should ignore them.
Add New Frame
- First, add new package by right click Source Packages, choose New - Java Package...
- Set Package Name = package01, click Finish button.
In Projects tab has added package01 packages.
- 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.
- Set Class Name = Frame01.
In this case, we will add JButton control.
- Add JPanel container.
In Palette tab, Swing Containers subtab, click Panel container (not drag), then put panel by clicked frame, and set the measurement.
- Change panel's layout by right click its panel, choose Set Layout - Null Layout. Null Layout give ability to positioning/measuring a control independently.
- In Palette tab, Swing Controls subtab, click Button control (not drag), then put it by clicked panel, and set the measure.
Now assign a command, when the button was clicked.
- Right click jButton1, choose Events - Action - actionPerformed.
- Insert following command in jButton1ActionPerformed :
JOptionPane.showMessageDialog(null, "Hello Netbeans.");
notice the case-sensitive.
- But there is an error symbol. To solve it, click that symbol and choose Add import for javax.swing.JOptionPane.
- When run program directly, it will be showed Project01View.java by loading Project01App.java. To showing Frame01.java file:
right click Project01 node, choose Properties...
- In Categories choose Run, then browse... Main Class file.
- Choose package01.Frame01.java, click Select Main Class.
- Run a program by hit F6, or the following toolbar:
.
- The Frame would be showed after click jButton1.
- 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.