In this section, you will learn how to display image on the frame. This program shows you how to display image in your application.
In this program, there are three methods have been used to display the image on the frame in your application. These are explained below :
This is the main() method of the program from which your program starts to execute the program in sequence. This method has simply create the instance for the AwtImage class.
This is the constructor of the AwtImage class in which, the instance of the MediaTracker class has been created to add the image on the frame using the addImage() method of the MediaTracker class. This constructor set the size, visibility and the close operation on the close button of the frame.
MediaTracker is the class of java.awt.*; package, has been used. MediaTracker is a utility class that tracks the status of a number of media objects. And this type of object can include images and audio clips. In this program only the explanation about the adding images has been given. MediaTracker class is used after creating the instance for that and calling the addImage() of the MediaTracker.
This is the addImage() method of the MediaTracker class which is used load the image. Then the addImage() method of the MediaTracker has been used. Syntax of the addImage() function is MediaTracker.addImage(img, x, y, x1, y1). Arguments of addImage() function is explained below :
img - image name type of Image.
x - lower X - Coordinate type of int.
y - lower Y - Coordinate type of int.
x1 - upper X - Coordinate type of int.
y1 - upper Y - Coordinate type of int.
Here is code of the program :
Liked it! Share this Tutorial