My first introduction to Java Applets

java
java

My first introduction to Java Applets

Welcome to CodeSpread!

What is it?

An applet is a class file that is written to display graphics in web browser. We embed applets using <APPLET> HTML tags. When run in a web page, java applets are downloaded automatically and run by the web browser.

Now we will see how applet works using AWT(Abstract Windowing Toolkit) :

Most basic AWT class is java.awt.Componenet class, which all AWT visual components are based on. This class is directly derived from java.lang.object class. Another important AWT class is Container class. This class is derived from AWT Component class and it is the basis of AWT Containers, which can hold other components.

Hierarchy of APPLETS

java.lang.object

——– java.awt.Component

—— java.awt.Container

—– java.awt.Panel

—— java.applet.Applet

Example:


import java.applet.Applet

import java.awt.*;

/*

<Applet

CODE=applet.class

WIDTH=300

HEIGHT=200>

<Applet/>

*/

public class applet extends Applet

{

public void paint(Graphics g)

{

g.drawString("Hello, Welcome to the java world!!");

}

}

Explanation:

Paint method is used to display message in the applet. It is inherited from Component class. When applet is displayed paint method is called and we can place the code for drawing the applet in that method. This method is passed as object of the Graphics class. This object supports a method “drawString” which is used to draw string of text in the applet.

Graphics class is an AWT class, sowe import AWT class when we override the default paint method of the applet class.

Attributes of <APPLET> tag


<APPLET

[CODEBASE =  URL]

CODE = filename

[ALT = alternateText]

[NAME = instancename]

WIDTH = pixels

HEIGHT = pixels

[ALIGN = alignment]

[VSPACE = pixels]

[HSPACE = pixels]

>

[<PARAM  NAME = name  VALUE = value >]

</APPLET>

Explanation :

  • CODEBASE – The URL that specifies the directory in which the applet code is to be found.
  • CODE – The name of the applet file, including the extension .class.
  • ALT – The text to be displayed if a browser supports applets but cant run this one for some reason.
  • NAME – The name of the applet in the web browser. Applets must be given names if we want other applets to be able to find & interact with them.
  • WIDTH – The width of the space reserved for the applet.
  • HEIGHT – The height of the space reserved for the applet.
  • ALIGN – Specifies the alignment of the applet. LEFT, RIGHT, TOP, BOTTOM, MIDDLE, BASELINE, TEXTTOP, ABSMIDDLE or ABSBOTTOM.
  • VSPACE – The space allocated above & below the applet.
  • HSPACE – The space allocated to the right & left around the applet.
  • PARAM NAME – The name of a parameter to pass to the applet.
  • PARAM  VALUE -  The value of a parameter.

The result of the above code appears as :

java applet

java applet

 

Author: swatiS

Share This Post On

0 Comments

  1. nice superb explaination

    Post a Reply
  2. thanks for the tutorial
    I am having a problem.
    The feature “Create SQL server database” isn’t available , I can’t select it.
    Can you help, please ?

    Post a Reply

Submit a Comment

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

More from CodeSpread:

  • Windiff saved my effort. How it is useful?Windiff saved my effort. How it is useful?While working with TFS [Team foundation server],we get used of the compare feature to compare the 'local version', 'server version','workspace version'. We had some similar situation when we rec...
  • Interview Series: Polymorphism Question- Answer UpdatedInterview Series: Polymorphism Question- Answer UpdatedWe are sharing our third question of the series in the form of comic, Please help our kid in the comic by sharing your answers through comments or Facebook  or Google plus or twitter[@CodeSpreadBlo...
  • Time Out: Not a Technical postTime Out: Not a Technical postTaking my time-out from technical world for once and sharing a regular joke in the form of  this comic with you. There is no harm in showing funny side also sometimes. wat say!!
  • YSlow is a nice addon to determine page performanceYSlow is a nice addon to determine page performanceYSLOW is one handier tool for a developer. It is used to analyze web pages and get it tested on the rules identified which are explained below. I like the name “YSlow”as it more or less poses a que...
  • Java script rendered content is not crawl able.Java script rendered content is not crawl able.There was a requirement to include 'ratings and reviews' plugin on the product pages of our website which is provided by a third party. We included a javascript library and some code as provided by...
  • ASP.NET and Web Tools 2013.1 for Visual Studio 2012ASP.NET and Web Tools 2013.1 for Visual Studio 2012.NET Web Development and Tools group at Microsoft announces release of ASP.NET and Web Tools 2013.1 for Visual Studio 2012. Few of the features are: 1) Round tripping: With this update, developer...
  • SQL Tables,Temporary Tables,Table VariablesSQL Tables,Temporary Tables,Table VariablesSQL provides a variety of Tables. Lets summarize each one of them. Permanent Tables: Why do we require it? It is required for data persistence across the database. Once tables are created ...
  • VB.Net: Download file from FTP and UnZipVB.Net: Download file from FTP and UnZipExperience: Many application requires data migration tasks to execute on daily basis. To achieve this we generally seek help of SSIS package, if at all we are making use of SQL sever. ...