9.15.7 Build Code for the Delete Button Method to Delete Course Records
The function of this method is to delete an existing course record from our Course Table when the Delete button is clicked by the user. The existing course record will be perma-nently deleted from the Course Table in our sample Oracle database when this method is complete.
Open the Delete button’s event handler and enter the code shown in Figure 9.97 into the event handler. Let’s have a closer look at this piece of code to see how it works.
A. Two local variables, delete and cfield[], are created first. The former is a Boolean variable used to hold the run result of execution of the Web service operation DeleteCourse(), and the latter is a JTextField array used to hold all TextFields in our CourseFrame Form. The purpose of using this JTextField array is to make it easier to clear all TextFields when this delete action is executed.
B. A try-catch block is used to call our Web operation DeleteCourse() to delete an existing course record via our Web service. First a new Web service instance, service, is created based on our Web service class, WebServiceCourse _ Service. Then a system method, getWebServiceCoursePort(), is executed to get the current port used by our Web service. This port is returned and assigned to a new port instance, port.

FIGURE 9.97 The completed code for the DeleteButtonActionPerformed() event handler.
C. The Web service operation DeleteCourse() is called to delete an existing course record from our Course Table based on the selected course _ id. The run result is returned and assigned to the local variable delete.
D. If a false is returned, which means that this course data delete has failed, the system println() method is used to indicate this.
E. Otherwise, the data delete is successful. A for() loop is used to clean up all six TextFields to indicate this situation, too.
F. The catch block is used to track any possible exception during the data delete process.
Now we have finished the coding process for calling and executing our last Web service opera-tion, DeleteCourse(), to delete an existing course record from the Course Table based on the selected course _ id. Click on the Clean and Build Main Project button to build our project. Click on the Run Main Project button to run our client project to test the course data delete function.
In the opened client project, keep the default faculty member Ying Bai unchanged and click on the Select button to query all course _ id taught by this selected faculty member. Immediately you can see that all five courses (course _ id) taught by this faculty member have been returned and displayed in the Course ID ListBox. To delete an existing course, CSE-549, just click on the course _ id from the Course ID Listbox and click on the Delete button.
To confirm the course delete action, two methods can be utilized. First, one can use the Select button to retrieve the deleted course from our database. To do that, just keep the selected faculty mem-ber Ying Bai in the Faculty Name combo box unchanged and click on the Select button. It can be seen that all returned courses (course _ id) taught by the selected faculty member are displayed, but without CSE-549. Another way is to open our Course Table in our sample database in the Services window inside the NetBeans IDE 12.0 to check whether this course has been deleted.
At this point, we have finished building and developing a Windows-based project to consume our Web Service project for the Course Table in our sample database. A complete Window-based cli-ent project, WinClientCourse _ UpdtDelt, can be seen in the folder Class DB Projects\ Chapter 9 that is in the Students folder at the CRC Press ftp site (refer to Figure 1.2 in Chapter 1).
Next let’s build a Web-based client project to consume this Web service.