Professional Documents
Culture Documents
Applet Definition
1. Import statements:
z import IntArrayBag;
z import java.applet.Applet;
z import java.awt.*;
z import java.awt.event.*;
2. Class Definition:
public class BagApplet extends Applet
{
//Declare an IntArrayBag for the applet to manipulate
IntArrayBag b = new IntArrayBag();
…
}
Sample code:
Button sizeButton = new Button (“size()”);
TextField elementText = new TextField (10);
TextArea feedback = new TextArea (7, 60);
Canvas line = new Canvas ( );
4. init method:
z A method that will be run when the
applet is activated
z Similar to “main” in an application
z Note: “init” is not a static method
Applet Definition
5. Implementation of action listeners:
Action listeners are methods to be activated
when actions occur (e.g. buttons are
pressed)
Sample:
| requestfocus( )
| selectAll( )
Applet Definition
| Compile as usual
| Create an html file (in the same directory as the
applet) that looks like this: