Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

JDBC Netbeans Graphical User Interface Programming

 STEP ONE
Create the Project.
i. Choose File > New Project. In the Categories pane, select the Java. In the
Projects pane, choose Java Application. Click Next.
ii. Type Addition in the Project Name field
iii. Uncheck the Create Main Class checkbox.

iv. Click Finish.


Addition is now part of the project
STEP TWO
Create a JFrame container

i. In the Projects window, right-click the Addition node


ii. choose New
iii. select JFrameForm
iv. and Click Next.
Enter AdditionUI as the class name.
Enter AddNumber as the package.

Click Finish.
The IDE creates the AdditionUI.java

Adding controls to the form.


i. Click on control such as label, textfield, button and
drop them on the form

1.
Renaming the Components
i. .
ii. Double-click jLabel1 and change the text property to First Number:.
iii. Double-click jLabel2 and change the text to Second Number:.
iv. Double-click jLabel3 and change the text to Result:.
v. Delete the sample text from jTextField1. You can make the display text editable by
right-clicking the text field and choosing Edit Text from the popup menu. You may have
to resize the jTextField1 to its original size.
Repeat this step for jTextField2 and jTextField3.
vi. Rename the display text of jButton1 to Clear. (You can edit a button's text by right-
clicking the button and choosing Edit Text. Or you can click the button, pause, and then
click again.)
vii. Rename the display text of jButton2 to Add.
viii. Rename the display text of jButton3 to Exit.
Your Finished GUI should now look like the following screenshot:
i. Add functionality to exit button

Right click the Exit button. From the pop-up menu choose Events > Action >
actionPerformed. The IDE will open up the Source Code window and scroll to where
you implement the action you want the button to do when the button is pressed. Enter
the line of code System.exit(0);. As shown below

// TODO add your handling code here:


System.exit(0);
ii. Add functionality to clear button

Right click the Clear button select Events > Action > actionPerformed. Control is transferred to
code window. Add the following lines of codes as shown below
// TODO add your handling code here:
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
iii. Adding functionality to add button

Right click the Add button select Events > Action > actionPerformed. Control is transferred to
code window. Add the following lines of codes as shown below

// TODO add your handling code here:


float num1, num2, result;
num1 = Float.parseFloat(jTextField1.getText());
num2 = Float.parseFloat(jTextField2.getText());
result = num1+num2;
jTextField3.setText(String.valueOf(result));
Run the program:

To run the addition project, Right click on AdditionUI.java in addition project and click
on run file. The GUI application will be up and running as follows:
Enter 22 in the textfield for first number
Enter 30 in the textfield for second number
Click on the add button and the result is 52
Assignment
Modify the user interface for addition to implement the following user interface for arithmetic
operations

ARITHMETIC OPERATION

FIRST NMBER

SECOND NUMBER

RESULT

ADDTION SUBTRACTION DIVISION

MULTIPLICATIO MODULO CLEAR EXIT


N

You might also like