Creating and Running the Applet

The folder view of the project is shown in the below image.

Step 1: First, create the file as AppletImage.java and enter the code into it.

Step 2: Once the code is been inserted then we need to create the AppletImage.html file, through which we will display the output.

HTML




<!DOCTYPE html>
<html>
<head>
    <title>Image Applet</title>
</head>
<body>
    <applet code="AppletImage.class" width="300" height="300">
    </applet>
</body>
</html>


Step 3: We need to have the image which we need to display in the applet. Here, we have used the gfglogo.png which is present in the code directory.

Step 4: Then we need to compile the Java code using the below command:

javac AppletImage.java

Step 5: Now finally we need to run the application using the below command:

appletviewer AppletImage.html

How to Display Image using Applet?

In this article, we will be using the Applet to display the image in proper layout. Here, we will display the image along with the text in the Applet Viewer.

Similar Reads

Approach for Displaying Images Using Applet

We need to import the essential packages like Applet and AWT for customization. When the packages get imported, then we need to create the class that implemented the ActionListener interface in Java. After that, we have to initialize the UI component of the Image. After initializing the component, we used the init() method in Java to load the image from the local storage. We will be displaying the GFGLOGO in the applet. Then, we have to define the paint() method, which will help render the content inside the Applet window. We will make the HTML file to run the applet. We have to compile the Java code using Javac and then we need to run using appletviewer....

Creating and Running the Applet

The folder view of the project is shown in the below image....

Program to Display Image using Applet

...