Swing GUI Hello World Example

Swing GUI Hello World Example

Creating GUI with Swing is very easy if you use NetBeans IDE because it generates all the skeleton code on the fly. In this example I will show how to create simple hello world application using Swing.

Tools needed:

  • NetBeans IDE (Version 8.0.2 has been used)
  • JDK 7

Steps:

  • Please download and install NetBeans IDE on your computer from here
  • Open your NetBeans IDE –> Click File new project –> Java –> Java Application

Swing GUI Hello World Example

  • Give project name then click finish:

Swing GUI Hello World Example

  • You will see below project got create as below:

Swing GUI Hello World Example

  • Add JFrame: Right click package swingHelloWord –> New –> JFrame Form…

Swing GUI Hello World Example

  • Give name of JFrame then click finish:

Swing GUI Hello World Example

  • You will new JFrame from got create as below:

Swing GUI Hello World Example

  • Now add button on it: On right hand side Palette window drag and drop button and give name Click Me:

Swing GUI Hello World Example

  • Right click button –> Edit text –> Write Click Me
  • On right hand side on button properties window change font to bold:

Swing GUI Hello World Example

  • Click event to generate code on action performed on button –> On properties window click event –> actionPerformed –> choose default method:

Swing GUI Hello World Example

  • Now click source tab to see generated java code and below line to change button text on click:

jButton1.setText(“Swing Hello World!!!”);

Swing GUI Hello World Example

  • We are done with code. To run –> Right click JavaHonkJFrame.java –> Run File:

Swing GUI Hello World Example

Swing GUI Hello World Example

  • Click the button you will below Hello World text:

Swing GUI Hello World Example

  • That’s it. For more details of Swing please visit Oracle documentation here

Leave a Reply

Your email address will not be published. Required fields are marked *