-
applet
import java.awt.*;
import java.applet.Applet;
public class applet1 extends Applet
{
String m;
public void init()
{
m = "hello world";
}
public void start()
{
}
public void paint(Graphics g)
{
g.drawString(m,10,10);
}
}
The init() method used in the java applet is simular to the contructor defined in a java application. The purpose of the init() method is to initialize a variable. This method is first called by the browser and it's a one time operation.
Once the init() method is invoked then the browser will call the start() method automatically. The start() method is used to start a thread as an example. The start() method is invoked each time it losses and gain focus.
Then the paint() method is invoked. The purpose of the paint() method is to draw itself. There are two ways in which this paint() method can be triggered.
1. System triggered painting
- Invoked by the awt.
2. Application triggered painting
- Invoked by using the repaint() method.
Question
1. Why is it that without defining the init() and the start() method, the paint() method can still be invoked? Is it because the paint() method is triggered by the environment?.
Last edited by solomon_13000; 06-23-2009 at 09:54 AM.
Similar Threads
-
Replies: 1
Last Post: 06-13-2008, 08:11 AM
-
By Tataroz T. in forum Java
Replies: 1
Last Post: 10-20-2005, 06:19 AM
-
Replies: 1
Last Post: 10-07-2005, 08:51 AM
-
By Charlie Flynn in forum Java
Replies: 3
Last Post: 08-23-2001, 11:01 AM
-
Replies: 0
Last Post: 03-28-2000, 01:52 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks