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
- Give project name then click finish:
- You will see below project got create as below:
- Add JFrame: Right click package swingHelloWord –> New –> JFrame Form…
- Give name of JFrame then click finish:
- You will new JFrame from got create as below:
- Now add button on it: On right hand side Palette window drag and drop button and give name Click Me:
- Right click button –> Edit text –> Write Click Me
- On right hand side on button properties window change font to bold:
- Click event to generate code on action performed on button –> On properties window click event –> actionPerformed –> choose default method:
- Now click source tab to see generated java code and below line to change button text on click:
jButton1.setText(“Swing Hello World!!!”);
- We are done with code. To run –> Right click JavaHonkJFrame.java –> Run File:
- Click the button you will below Hello World text:
- That’s it. For more details of Swing please visit Oracle documentation here