Applet Programming
Applet Programming
➢Graphics
public void paint (Graphics g)
Chain of classes inherited by Applets
java.lang.Object
java.awt.Component
java.awt.Container
java.awt.Panel
java.applet.Applet
Applet Life Cycle
• Born on initialization state
• Running state
• Idle state
• Dead or destroyed state
Initialization state
• Enters initialization state when
first loaded
• init() method
• Occurs only once
<APPLET
CODE = helloJava.class
WIDTH = 400
HEIGHT = 200 >
</APPLET >
2. Java appletviewer
Passing Parameters to Applets
• We can supply user-defined parameters to an applet using <PARAM ... > tags.
• Each <PARAM ... > tag has
➢a name attribute such as color, and
➢a value attribute such as red.
<APPLET>
<PARAM NAME= color VALUE= "red"> <PARAM NAME = text VALUE = "I love Java">
</APPLET>
2. Retrieve the items from the fields for display of calculations, if any.
• The text fields contain items in string form.
• Converted to the right form, before using in any computations.
• The results are then converted back to strings for display.
Run the applet
1. Type and save the program (.java file)
2. Compile the applet (.class file)
3. Write a HTML document (.html file)