A. Some local objects are declared first, which include a byte[] array object, bimg, and an Image object, img, and both objects are used to hold the created byte[] image array and converted Image object. Both integer variables, imgId and timeout, are used to keep the image ID and timeout value when displaying this image in the Canvas object in our client.
B. A try-catch block is used to call our Web service to perform the faculty data query operation. First a new Web service instance, service, is created based on our Web ser-vice class WebServiceFaculty _ Service. Starting with NetBeans IDE 7, a keyword _ Service must be appended after the Web Service name to create a new service object.
C. The getWebServiceFacultyPort() method is executed to get the current port used by our Web service. This port is returned and assigned to a new port instance, port.
D. Now our Web Service operation, QueryImage(), is called with the selected faculty name as the argument to retrieve the selected faculty image from our sample database and assign it to our local variable bimg. One issue is that this returned object is an Image type when it is defined in our Web Service, but now we are using a byte[] array data type to hold this image. The reason for that is the default conversion by NetBeans IDE.
E. Two code lines in this section are used to convert the data type of this returned image from byte[] to Image. A ByteArrayInputStream object and ImageIO.read() method must be used for this conversion.
F. A catch block is used to detect and report any error for the conversion process.
G. In order to store our retrieved faculty image in our current project folder, the system method getProperty() with our current directory (user.dir) is used, and the current folder is assigned to a local string variable, imgPath.
H. To get the selected faculty image, we need to get the current selected or queried faculty name from the Faculty Name combo box, convert this item to a string and attach “.jpg” to the image file name. We need to use the name of this faculty image later to store and display this selected faculty image in the Canvas.
I. To save this converted faculty image in our current project folder, a new File object is gen-erated with the image path and name. A system method, ImageIO.write(), is used to complete this image-saving job.
J. To display the selected faculty image, the getImage() method that belongs to the abstract class Toolkit is executed to load the selected image. Since the Toolkit class is an abstract class, we use the getToolkit() method to create it instead of generating it by invoking its constructor. The getGraphics() method is called to get a Graphics context, and our ImageCanvas works as an image holder for this faculty image.
K. The addImage() method that belongs to the MediaTracker class is called to add our image with its ID into the tracking system.
L. A try-catch block is used to begin a tracking process, and the waitForID() method is called to execute the tracking. If a timeout occurs for the tracking process, which means
that the selected faculty image has not been loaded into the project, a warning message is displayed using our MsgDialog object, and a False is returned to indicate this error.
M. Any other possible exception or error will be caught by the catch block and be displayed in our msgDlg dialog.
N. If no timeout error happens, which means that the selected faculty image has been loaded into our project and is ready to be displayed, the drawImage() method is executed to dis-play it in the FacultyFrame Form window. We want to display this image starting from the origin of the Canvas object, which is the upper-left corner of the canvas (0, 0), with a width and height that are identical to those of the canvas. Therefore, the getWidth() and getHeight() methods are called to get both of them from the canvas object. A true is returned to the main program to indicate that the execution of this method is successful.
Before we can build and run our client project to test this faculty query, add one more code line, System.exit(0); to the bottom of the BackButtonActionPerformed() handler or method in the Source window of the FacultyFrame class to terminate our project if the Back button is clicked.
Now we are ready to build and run our client project to test its function to call our Web service to perform the faculty data query.