GUI NetBeans 2021
GUI NetBeans 2021
1
Create a New Package inside the Project:
2
Creating a JFrame Form
3
Navigating the JFrame Form
1. Add Label and Text Field for each item: Product Code, Product Name, Unit Price, Quantity,
Amount.
2. Add a Button: Compute and Clear
3. Make sure to change the Variable Name of each of your controls. The Variable Name will be
your reference when writing your codes.
Quantity txtqty
Amount txtamount
Compute btncompute
Clear btnclear
4
This will be the entire look of the form after you have placed the necessary controls.
5
Writing Codes or Events
1. For the events, there are codes which are needed to be placed on the following: Compute
button, Clear button, and other parts.
2. Just double click on the button and insert your codes.
Please note that all the text fields are String data. Therefore, if you need to calculate, you have to
convert these String data into numeric. Some explanations of the codes:
// temporary variables for calculation
String stramount;
// calculate the vamount using vuprice, vqty which are double data
vamount = vuprice * vqty;
6
4. You can try running the form even if the codes are not completed yet.
5. Codes in the Clear button = btnclear.
txtpcode.setText("");
txtpname.setText("");
txtuprice.setText("");
txtqty.setText("");
txtamount.setText("");
// disable the button Compute so that if the other fields needed for
//calculation are empty, errors may be prevented.
btncompute.setEnabled(false);
Will enable the Compute button after txtqty field has been inputted.
7
7. Place initializations after the initComponents( ); found on the upper part of the entire Source.
Notice that the same codes are applied in the initializations as in the Clear button. This means
that a fresh start of text field values are assigned at first, and the first focus will be on txtpcode.
Compute button, btncompute is disabled first since fields needed for computation are still empty.
8. Your form has been completed. Run them and if there are problems, review the codes and edit
them as necessary.
8
Advanced OOP
Activity No. 3
Applying GUI NetBeans
By: E.T. CAPARIÑO
1. Make sure you have tried the lecture about GUI Netbeans.
2. Run the form.
3. Paste some screen shots of the output here:
9
4. Remove the following from Clear button and the initialization.
btncompute.setEnabled(false);
5. Run the form.
6. Enter data for Product Code and Product name only.
7. Click the Compute button.
8. What output is produced? Placed screen shots here….
9. Do you think it is necessary to disable the Compute button? Why or why not?
10. Save this document (Activity No. 3) as PDF and send to Google Classroom.
10