Graphical User Interface (GUI)
A GUI (Graphical User Interface) allows users to interact with a Java application using windows,
buttons, text fields, menus, labels, etc., instead of typing commands.
Here are the clear, simple steps to create a Graphical User Interface (GUI) in Java using
NetBeans + Swing.
Steps to Create a GUI in Java (Using NetBeans)
1. Open NetBeans
Start NetBeans → Click File → New Project
2. Crete a Java Project
Select:
Java with Ant → Java Application
Click Next
Enter Project Name (Example: MyGUIApp)
Uncheck Create Main Class (optional)
Click Finish
3. Create a New JFrame Form
Right-click on Source Packages →New → JFrame Form
Give it a name, e.g. HelloForm.
NetBeans will open the Design Window.
4. Design the GUI (Drag & Drop)
From the Palette (right side), drag components:
Common components:
Label
Text Field
Button
Example layout:
Label: Enter Your Name:
TextField: txtName
Button: btnSayHello
Label: lblMessage
5. Change Component Properties
Click each component → Properties window → change:
text
font
name (important!)
Example:
TextField → Name: txtName
Button → Name: btnSayHello
Label → Name: lblMessage
6. Add Event: Button Click
Double-click the button → NetBeans opens code:
private void btnSayHelloActionPerformed([Link] evt) {
String name = [Link]();
String message = "Hello " + name;
[Link](message);
}
Explanation:
name stores text entered by the user.
message joins the text "Hello " with the user's name.
[Link]() displays the message on the label.
7. Run the GUI Program
Click the Run (▶ Run Project) button.
Your GUI window will appear.
Example Output
If the user types: Awoke
Label shows: Hello Awoke