Display an Image for the Selected Faculty Member in Canvas 2 – Querying Data from Databases

As we know, every AWT component object has a Graphics context, and the real drawing is done in the paint() method of a component because paint() is called by AWT automatically when the image is finished loading. However, an important issue is that image loading is an asynchronous process, which means that loading does not necessarily occur until you attempt to display the image via drawImage(). The last parameter to drawImage() specifies which component to repaint when the image is finally ready. This is normally the component that calls drawImage() in the Java GUI container.

In fact, when the first step, loading an image, starts, the getImage() method kicks off a new thread to load and fetch the image, and this thread does not start immediately or synchronously when you run the loading method. Instead, this thread will not begin its process until the drawIm-age() method is called. Therefore, it is not guaranteed that the required image will be loaded and ready to be displayed when drawImage() is executed.

In order to solve this asynchronous problem in image loading and display, another image-related class, MediaTracker, is used to monitor and track the run status of the image loading process. MediaTracker is a utility class designed to track the status of media objects. In theory, media objects could include audio clips and other media as well as images. You can use a media

tracker object by instantiating an instance of MediaTracker for the component that you want to monitor and invoking its addImage() method for each image that you want to track. Each image can be assigned a unique identifier starting from 1, or groups of images can be assigned the same identifier. You can determine the status of an image or group of images by invoking one of several methods on the MediaTracker object and passing the identifier as a parameter to the method.

Another way you can use the MediaTracker object is to block and wait until a specified image or group of images completes loading. We will use this approach in this project to make certain that a desired faculty image has completed loading before we attempt to draw it.

Before we can start this image-displaying process with code, we need first to create a user- defined method to include our code in this customer-made or user-defined method to identify, select and display the desired faculty image via the FileOutputStream object defined in the Java Swing windows group.

Leave a Reply

Your email address will not be published. Required fields are marked *


© 2024 vogafloat, LLC ,About, Careers, Contact us,Cookies, Terms, Privacy