You are on page 1of 5

Applet structure

<import Class Packages>

public class <ClassName> extends <Package>


implements <Action/Event>
{
<Declaration>;

Public void int()


{
Initialize objects;
}

Public void <Action/Event>(variable Class)


{
Events;
}
}

Sample Java applet

Package Import

Import java.<MailClass>.<Component>

Ex:
Import java.awt.*; - All Components
Import java.awt.Button; - All buttons
Import java.awt.TextField; - All Text
boxes

Paint()
Syntax

public void paint(Graphics g)


{
g.drawString(Statement,X-Pos,Y-Pos);
}

HTML File

Syntax

<Applet code=ClassFileName.class
width=value Height=value>
</applet>

Execute Applet
Syntax

Appletviewer <htmlfile>.html

Ex:

Appletviewer Welcome.html

Applet Methods

drawstring()

g specify that it was a member of the graphics class

g.drawString(Statement,X-Pos,Y-Pos);

drawLine()

Syntax
g specify that it was a member of the graphics class

g.drawLine(X1-Pos,Y1-Pos,X2-Pos,Y2-Pos);

ex:
g.drawLine(50,50,100,85);

(50,50)

(100,85)
drawRect()

Syntax
g specify that it was a member of the graphics class

g.drawRect(X1-Pos,Y1-Pos,DistanceX,DistanceY);

Ex:
g.drawRect(50,50,50,35);

(50,50) 35

50

Change Applet Fonts

Font()
Syntax

Font <Variable>=new Font(Font


Name,Font.<Style>+ Font.<Style>,Size);

Ex:

Font myFont=new Font(Book


Antiqua,font.BOLD+font.ITALIC,24);

Font Initialization

Syntax

<Graphics Variable>.setFont(<font Variable>)


<Graphics Variable>.drawString(Statement,X-Pos,Y-
Pos)