Java Applet - Creating First Applet Example

First of all we will know about the applet. An applet is a program written in java programming language and embedded within HTML page.

Java Applet - Creating First Applet Example

First of all we will know about the applet. An applet is a program written in java programming language and embedded within HTML page.

Java Applet - Creating First Applet Example

Java Applet - Creating First Applet Example

     

Introduction

First of all we will know about the applet. An applet is a program written in java programming language and embedded within HTML page. It run on the java enabled web browser such as Netscape navigator or Internet Explorer.

In this example you will see, how to write an applet program. Java source of applet is then compiled into java class file and we specify the name of class in the applet tag of html page. The java enabled browser loads class file of applet and run in its sandbox.

Here is the java code of program :

import java.applet.*;
import java.awt.*;

public class FirstApplet extends Applet{
  public void paint(Graphics g){
  g.drawString("Welcome in Java Applet.",40,20);
  }
}

Here is the HTML code of the program:

<HTML>
<HEAD>
</HEAD>
<BODY>
<APPLET
ALIGN="CENTER" CODE="FirstApplet.class" WIDTH="800" HEIGHT="500"></APPLET>
</BODY>
</HTML>

Try online this example.

Download this example.

Tutorials

  1. What is an Applet
  2. The Life cycle of An Applet
  3. Java Applet - Creating First Applet Example
  4. Java - Drawing Shapes Example in java
  5. Java - Drawing Shapes Example using color in java
  6. Java - Event Listeners Example in Java Applet
  7. Applet - Passing Parameter in Java Applet
  8. Opening a URL from an Applet
  9. Java - Opening a url in new window from an applet
  10. Applet is not Working
  11. Display image in the applet
  12. Applet Write Files Example
  13. Play Audio in Java Applet
  14. Security Issues with the Applet
  15. Swing Applet Example in java
  16. The Sample Banner Example in Java
  17. Clock Applet in Java
  18. HTML Document Creation
  19. Tag Parameters: The Tag
  20. The APPLET Tag in Detail
  21. Java and HTML: The Basics
  22. What Exactly is HTML?
  23. Welcome to the Internet
  24. java.applet package examples
  25. java.applet package examples
  26. What is an Applet - Java Applet Tutorial
  27. Java - Read file Applet
  28. Applet versus Application
  29. Tag Parameters: The Tag
  30. Java - Opening a url in new window from an applet
  31. Java - Opening a URL from an Applet
  32. Applet Tag Parameters,Applet Tag in HTML
  33. Applets in Java
  34. What is Applet in Java?
  35. What is Applet in Java with Example?