Getting Started with GUI based Java Applications using NetBeans

Hello Everyone,

This is saif, enjoying cool evening with a cup of tea and writing this tutorial titled as “Getting Started with GUI based Java Applications using NetBeans”. This article is for beginners who want to get their journey started in programming world with GUI Applications using Java. It will also be helpful for those who are already familiar with Java or some other programming language and want to design GUI based java Applications.

This article will guide step by step how to make a GUI Application in Java using Netbeans as an IDE. Let’s Begin.

If you have no prior knowledge of Java and NetBeans read this article once to have a flavor.

Getting Started with NetBeans

  1. Download and install Java from heredownload java
  2. Download and install NetBeans from here
  3. Open NetBeans and Create a new projectnew project
  4. Select java -> Java Application from the dialog and then click nextjava Application
  5. Name your new project, uncheck ‘create main class’ option  and click on finishnew project
  6. Create a new package by right clicking on ‘source package’ as:
    new -> Java Packagejgui_n_3
  7. Name the Package and click finishjgui_n_4
  8. After creating a new package, create a  new ‘JFrame Form’ by right clicking on new package created (named as GUI):
    new -> JFrame Formjgui_n_5
  9. Name the new JFrame and click Finishjgui_n_6
  10. After performing the above steps, you will get the following window.
    jgui_n_7
  11. Project Window: Contains the project files in hierarchical order jgui_n_14
  12. Navigator: Provides hierarchical representation of all the project componentsjgui_n_17
  13. Palette: Contains the list of all GUI Components arranged in categoriesjgui_n_13
  14. Design Area: It is the window provided to create and edit GUI Forms. You can drag and drop components from palette here to design a GUI Application.jgui_n_15
  15. Properties Window: It displays all the properties and available events for currently selected Component in GUI builder or navigatorjgui_n_16
  16. Press F6 or click Debug to execute the program. You will get an empty Framejgui_n_8
  17. First of all, we will place a Title on the Frame. We have two methods to achieve this. Either right clicking on Frame in Design Area and selecting Properties Window or directly changing the title property in Properties Window located on bottom right.jgui_n_9jgui_n_10jgui_n_11
  18. Now after executing, our frame will look like this.jgui_n_12
  19. Let’s start with out first GUI Application. Drag and drop a Panel from Palette to the Design Form. Stretch it to the whole form.jgui_n_18
  20. Right click on Panel and set layout to ‘Absolute Layout’jgui_n_19
  21. Drag and drop one JLabel, one JTextField and one JButton on the Design form and arrange them as follows.jgui_n_20
  22. You can also select a single or multiple components form navigator to change its propertiesjgui_n_22
  23. Change JLabel text property to “Enter Your Name:”, JTextField to null and JButton to “Submit” using property windowjgui_n_21
  24. Change the variable names for Jlabel, JTextField and JButton to nameLabel, nameField and submit respectively by right clicking on each component and choosing Change Variable Name.jgui_n_23
  25. After changing components’ variable name, you can see the changes in navigator window.jgui_n_24
  26. Double click submit button on Design Form and you will be taken to the code view of this Form. You have just created a Listener for submit button. This Listener will called when you will press submit button after executing your Application. jgui_n_25
  27. Now we will place these two lines of code in it.
    String name = nameField.getText();
    JOptionPane.showMessageDialog(this, "Hello "+name+ "! Here is Your First GUI Application");
    jgui_n_26
  28. After completing above steps, press F6 to execute you Application. Enter you name in the text Field and press submit. You will get the following message-box.jgui_n_27
  29. To make ‘.jar’ file of you project, click on ‘clean  and built project’.jgui_n_29
  30. After successful build, you will get this outputjgui_n_28
  31. Then go to NetBeans Project folder. You will get the jar file inside dist folder
    NetBeansProjects\MyFirstGUI\dist
    You can directly execute you jar files.jgui_n_30

Congratulations 🙂
We are done with setting up Java and netbeans and successfully executing our first GUI based Java Application.

Stay with Protorials for more tutorials.
Have a nice day!

Advertisements

1 thought on “Getting Started with GUI based Java Applications using NetBeans”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s