Saturday, 10 August 2013

How to Design a Swing GUI using Netbeans


Some people may consider creating GUI with notepad a way to show their talent, But Why we use Calculators then when we know all the maths, Just to save our time....


Learn GUI building in Java/Swing in 5 simple step

Assuming that Java Development Kit (JDK) is installed in your System.If not first download and install it from here.

1.Install Netbeans IDE 

If you don't have Netbeans just download it from here. Just select the version you want according to your needs and operating System you use.Now that the download is completed, just double click the installer file and follow the on screen wizard .

2.Create a new java project

Select new package in the file option in the menu bar.
Lets give the project name Demo.



3. Create a new JFrame Form in the project Demo.

Double click on the project icon. Right click on so source packages, select New>JFrame Form.
Give a suitable name for the JFrame.Give a package name for this file.Click Finish.

4.Create GUI For a simple calculator

Drag&drop from the right side pallete window components which you want in you GUI.
For a simple calculator i used 2 textboxes,4 buttons.
Change the variable name and the properties according to your choice from right click menu.


5. Now the coding part

Declare and initialise the following variables just after the class Demo starts.


Select Event >Action Performed on + button and add the following code in the actionperformed method for + button. Put the code in a try-catch block.

Copy paste the above code in action performed for minus button and product button, with minor changes.

k=2// for minus
input =input+"-";

k=3// for multiplication 
input=input+"*";

Now add the following code in the click event of equal button

Select the frame from the left Navigator window and add event key> key typed. This part make sure that when we do any other operation after erasing the previous answer from TextBox2, TextBox1 gets erased for the new operation.
Our simple Calculator is ready For build and deployment.

1 comment:

  1. wow.... it's amazing.. thank you mr. Partha... The language is quite simple and snaps are really great...

    ReplyDelete