0% found this document useful (0 votes)
5 views2 pages

Java Lab-5

This document provides a step-by-step guide to creating a Graphical User Interface (GUI) in Java using NetBeans and Swing. It outlines the process from starting a new project to designing the GUI, changing component properties, adding event handling for button clicks, and running the program. An example output demonstrates how the GUI responds to user input.

Uploaded by

gadane720
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Java Lab-5

This document provides a step-by-step guide to creating a Graphical User Interface (GUI) in Java using NetBeans and Swing. It outlines the process from starting a new project to designing the GUI, changing component properties, adding event handling for button clicks, and running the program. An example output demonstrates how the GUI responds to user input.

Uploaded by

gadane720
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

You might also like