Introducing Java Applets
page 3 of 5
by Debjani Mallick
Feedback
Average Rating: 
Views (Total / Last 10 Days): 48089/ 83

Creating an applet program

Applet is a window based application. We need to import two packages for writing an applet program – java.lang.awt.* and java.lang.applet.*. The java.lang.awt.* package provides a set of classes and using those classes we can create a window component and it also contains a graphic class; the java.lang.applet.* package is used as we are using an applet class which is present in applet package.

Listing 3

import java.lang.awt.*;
import java.lang.applet.*;
public class classname extends Applet
{
  public void paint(Graphics g)
  {
    g.drawString(String,height,width);
  }
}

Public keyword is used because we run an applet program in a media different from that in which we write it. Paint() method used in the above example calls drawString() function which is a function of Graphics class. Applet class contains certain functions like init(), start(), stop(), paint(), destroy(), etc. which are usually used in programs.

init() method – Whenever an applet is loaded into a web page this method is automatically called. This method provides an appropriate place for initialization of the variables required and other set up operations such as setting of background color, defining the applet’s layout, parsing parameters, etc.

start() method – After the initialization is completed, start() method is called. The difference between this method and the init() method is that init() method is called only when the page is loaded, whereas start() method is called every time the page is loaded and every time the page is restarted. That is, if a user navigated from one page to another page and then he returns to the original page, start() method is called again but the init() method is not called again. This method is mainly used while implementing threads in Java.

stop() method – This method is called whenever the user navigates from one page to another page. It is always advisable to use stop() method if any type of animation or memory consuming activities is being performed in order to avoid wasting of system resources.

destroy() method – This method is called immediately before the applet exits. The exiting operation is caused by either the applet operation requesting for the exit or may be the web browser is shut down. When it is called it directs the applet to free up all the system resources being used by it.

paint() method – As mentioned earlier, this method is used to draw items.


View Entire Article

User Comments

Title: asd   
Name: asd
Date: 2012-11-29 7:57:45 AM
Comment:
asd
Title: Email Id Form in Java   
Name: Siva
Date: 2012-08-17 11:24:34 AM
Comment:
I want to know how to create email id form in java.
plz anybody known it plz upload it...
Thanks...
Title: applet   
Name: mayuri
Date: 2011-03-14 1:20:41 PM
Comment:
Its very helpfull to me,thanks
Title: applet   
Name: vida
Date: 2011-03-11 4:27:51 AM
Comment:
It was nice article & Very helpfull. Thank you.
Title: applet help   
Name: sam
Date: 2010-08-25 10:42:37 AM
Comment:
Thank you for the helpful and concise article. This was a good introduction to applets.
Title: Applets   
Name: veena
Date: 2010-04-19 6:40:44 AM
Comment:
easy understanding for the beginners
Title: Applets with asp.net   
Name: java
Date: 2010-02-12 12:47:23 PM
Comment:
See this article for info on how to integrate Java applets with asp.net
http://java.sun.com/developer/technicalArticles/appletAspIntegration/index.html
Title: query related to applets   
Name: mayank
Date: 2009-10-14 2:35:43 AM
Comment:
i m learning applet,can you please explain me how to write code for event handling in applets.if you know the answer then please mail to my email id mayank.mathur06@gmail.com.

Thank you.
Title: heyyyy   
Name: swathi
Date: 2009-08-10 3:47:13 AM
Comment:
its really very nice
Title: Applets   
Name: Anu
Date: 2009-07-23 1:56:43 PM
Comment:
It was a good article....you are doing a good job. Keeps on sharing your knowledge with others......thanks.
Title: Applets   
Name: Priya
Date: 2009-07-14 7:48:50 AM
Comment:
Hello,
awesome job!
Iam a learning applets and standing at initial stages.This article renders excellent learning resources with lots of examples written in short and sweet mannner that provide quick learning covering almost alll topics in short span of time.

Thanks and keep up the good work....
Title: Applets   
Name: Sutapa
Date: 2008-06-18 2:02:46 PM
Comment:
Really good article for beginners.....
Title: human face   
Name: ridima
Date: 2008-05-15 10:27:52 AM
Comment:
what if i have to run the human face applet from command prompt
it shows me an error that no main found
Title: java applets   
Name: kunwarjeet singh
Date: 2007-08-15 11:25:33 PM
Comment:
Too good for beginners.
Title: java applets   
Name: venkata subbaiah
Date: 2007-08-13 3:43:13 AM
Comment:
emerging one for quick learning
Title: Fabulous   
Name: Nikita
Date: 2007-07-22 9:06:43 AM
Comment:
Go on
Title: Too good   
Name: Fred
Date: 2007-07-18 11:53:32 AM
Comment:
Its a nice article for beginners
Title: good   
Name: Rishi
Date: 2007-07-13 1:10:32 PM
Comment:
A very good article
Title: Good   
Name: Chandrakanta Kar
Date: 2007-07-13 7:57:18 AM
Comment:
It is fundamental level article, any way nice
Title: abhi   
Name: gr8
Date: 2007-07-06 12:53:16 PM
Comment:
keep up the good work!!!!
Title: something really gooe   
Name: Surya
Date: 2007-07-06 12:18:03 PM
Comment:
Its really good
Title: Good one   
Name: sdwsadxa
Date: 2007-07-04 11:35:48 AM
Comment:
Keep it up
Title: Nice   
Name: Tim
Date: 2007-07-04 11:35:05 AM
Comment:
Nice job
Title: Good work   
Name: Sid
Date: 2007-07-04 11:34:34 AM
Comment:
The article is worth reading.
Title: Good   
Name: Nash
Date: 2007-07-03 3:21:39 AM
Comment:
Really helpful...good job

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2019 ASPAlliance.com  |  Page Processed at 2019-09-19 3:35:11 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search