Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Example Java Applet Applets in Java

Related Tutorials


 
 

Share on Google+Share on Google+

Applets in Java

Advertisement
Applet is a Java program embedded within HTML pages. Java applets is compatible with almost all the web browsers like Mozilla Firefox, Google Chrome, Internet explorer, Netscape navigator and others that are java enabled. Applets make a website more dynamic and are secure.

Applet is a Java program embedded within HTML pages. Java applets is compatible with almost all the web browsers like Mozilla Firefox, Google Chrome, Internet explorer, Netscape navigator and others that are java enabled. Applets make a website more dynamic and are secure.

Applet is designed to run remotely on the client browser. They cannot access system resources on local computer. They are often used for a small internet and intranet applications.

Following example will show how to develop an applet code that displays Hello World message and run it in the browser.

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class HelloWorldApplet extends Applet{
  public static void main(String[] args){
  Frame frame = new Frame("Roseindia.net");
  frame.setSize(400,200);
  Applet app = new HelloWorldApplet();
  frame.add(app);
  frame.setVisible(true);
  frame.addWindowListener(new WindowAdapter(){
  public void windowClosing(WindowEvent e){
  System.exit(0);
  }
  });
  }
  public void paint(Graphics g){
  g.drawString("Hello World!",200,100);
  }
}

Here is the HTML code required to Run an applet in web browser:

<html>
<head>
<title>A Simple Applet program</title>
</head>
<body>
<APPLET CODE="HelloWorldApplet.class" WIDTH=700 HEIGHT=500>
</APPLET>
</body>
</html>

The Applet tag in html is used to embed an applet in the web page.

<APPLET CODE="HelloWorldApplet.class" WIDTH=700 HEIGHT=500>

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: May 11, 2013

Related Tutorials

Discuss: Applets in Java  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com