An introduction to Java NetBeans

IDE

IDE Stands for integrated development environment. It is a place where we can design the page, write the source code, debug the source code, compile and execute the code. Examples of IDEs include, Eclipse, My eclipse, RAD, Jboss, Netbeans, etc.

Net beans IDE:

Net beans is a free open source, cross-platform IDE with built-in support for Java. It offers many features such as:

  • Drag and Drop GUI Reaction
  • Excellent editing
  • Web services
  • Excellent debugging
  • Wizards, code generation, and management tools
  • And much more

The major windows available in net beans IDE are:

Palette: contains a customizable list of available components containing tabs for JFC or swing, AWT, and Java beans components. In addition we can create, remove, and rearrange the categories displayed in the palette using the customizer.

Inspector Window or Navigator: provides a graphical representation of all the components in our application, both visual and non-visual, in a true hierarchy. The inspector window also provides visual feedback about the component in the frame that is being edited in the GUI builder, and it allows us to organize components in the available panels.

Properties Window: displays the properties of the component currently selected in GUI builder, Navigator, components window, and files window. It helps us to change the appearance and behavior of the components.

Project Window: the area where all user defined projects are available.

Design Area: the GUI builder’s primary window for creating and editing GUI forms. The toolbar source and design toggle buttons enable us to view the source code or a graphical view of its components.

Source Area: where we write or edit the source code for the designed application.

Creating a project in NetBeans (considering the name of the project is book):

Step1: Choose file, menu, new project. You can also click on the new project icon in the standard tool bar.

Step 2: Select Java from the categories pane, then select java application from the projects pane and click Next.

Step3: Enter the name of the project in the project name field and specify project Location by clicking on the browse button. By default the folder in my documents’. The project will be saved in the NetBeans project folder in “My Documents”

Step 4:Ensure that the create main class box is not checked.

Step 5:Click finish.

Java swing user-interface:

Jframe:

Every swing application must have at least one top container swing that provides three useful top-level containers, i.e., JFrame, JApplet, JDialog. However, out of these three, the most commonly used is JFrame.

  • A frame is a top level window with a title, border, and optional menu bar that can hold other components placed by the user on the frame. Default, close operation, and title are some of the properties of transform.

Jlablel:

A child-level component that directs the user what to what has to be performed on another component. It is also helps us to display an image on the form.

JTextField:

A child-level control that helps enter single-line inputs and displays. The single-line output is in a human-readable format.

JTextArea:

A component that allows the user to enter multiline inputs that are displayed, but it won’t work automatically. Whenever the end-user tries to enter the content in the text area component, it will display the content in a single-line with the help of horizontal and vertical scrollbars. For the multi-line display to work, we need to apply two important properties, i.e., line-wrap and wrap-style.

JPasswordfield:

A component that allows the user to enter a single line of text in an encrypted format.

JRadioButton:

A component that allows the user to select one of multiple options on the frame, i.e., it is mutually exclusive. However, it won’t work automatically. In order for it to work according to the definition of a radio button, we need to use another component called Button Group. Button Group is an invisible component that we use when we drag Button Group from palette to the Design area – we cannot see Button Group component on the frame. To check if it has actually been added, check the inspector window under other components. Now, add all the RadioButtons that belong to one particular group to the Button Group using the ctrl key.

JCheckBox:

A component that allows the user to select multiple options on the frame.

JComboBox:

A component that allows the user to select one out of many options. JComboBox is available in the form of an editable JComboBox and an uneditable JComboBox.

Editable JComboBox comes with a text field and a drop-down list; whereas uneditable JCombobox comes with a button and a dropdown list. When we drag and drop a JComboBox from the palette to the design area, the default item names will item1, item 2, and item 3. To change the name of the JComboBox items, we have to use the model property.

JList:

A component that provides a scrollable set of items. One or more of these items may be selected.

JButton:

Provides the functionality of a button. It allows an icon, string, or both to be associated with the push button.

JPanel:

A lightweight container used for holding components (including a button label list, etc.) that allows the developer to have more control over the positioning and styling of widgets on the screen.

JPanels are fundamental in the creation of professional GUI.

JScrollPane:

Provides a scrollable view of components when the screen real state is limited. JScrollpane provides a way of scrolling horizontally and vertically if the widget becomes bigger than the view point size. It is primarily used in JTextArea and JLabel where the data displayed by the widget is changed dynamically and can really effect the size and dimensions of the widget.

JOptionPane:

We generally use JOptionPane when we want to request some information from the user, display some information to the user, or a combination of both.

It requires the following import statement at the top of the program:

import javax.swing.JOptionPane; (or) 
import javax, swing*;

JDialog():

A swing window dialog that provides the normal behavior of a window. It comes with minimize, maximize, and close options in the title bar of the dialog box. Most dialogs present an error message on the top, but JDialog presents images as well as tree structures.