This introductory tutorial will teach you how to create a simple Man-machine interface and add simple background functionality to it. In particular, we'll show you how to write control buttons and field codes according to the Swing specification.
We will use the layout management, design a simple GUI interface, and add some button and text field components. The text field is used to receive input and display output, and the button is used to start the corresponding function on the front end. The application we will create will be a simple but useful calculator.
For more GUI design features, videos, and documentation, see Desgning a Swing GUI in NetBeans IDE.
The software required for this tutorial
Please make sure that your computer has the following software installed:
NetBeans IDE 6.0
Java Standard Development Kit (JDK) version 5.0 or 6.0
Step 1: Create the project
The first step is to create an application and name it numberaddition.
Select "File"-> "New Project". Or, on the toolbar, click the New Project icon.
Select Java in the Categories pane of the pop-up window, and select Java application in the Projects pane. Click "Next";
Type numberaddition in the project name and type the local file directory in project location to save the project;
The Confirm CheckBox "Set as Main project" has been checked. And make sure the checkbox "Create main class" is not checked.
Click "Finish"
Step 2: Build the interface
Continue to create our interface. We need a Java container to place other GUI components that will be invoked. In this step we use the JFrame component as the desired container. We place the container in a new package that is located in the source package.
Creating a JFrame Container
Right-click Numberaddition in the Projects window and select New-> JFrame form.
In the class name item, type Numberadditionui.
Type My.numberaddition in the package item.
Click Finish.
The IDE creates the Numberadditionui form in the Numberaddition application based on the class Numberadditionui and opens the Numberadditionui form in the GUI Builder. Package My. Numberaddition is set to the default package.