360 likes | 650 Views
Applet. Small java program that execute on web browser Applet program placed in html File Applet is class available in java.applet package It contain three interfaces: AppletContext, AudioClip and AppletStub Types: Local Applet: Create in local computer and use in web pages
E N D
Applet Small java program that execute on web browser Applet program placed in html File Applet is class available in java.applet package It contain three interfaces: AppletContext, AudioClip and AppletStub Types: Local Applet: Create in local computer and use in web pages Remote Applet: Download from other Computer or internet and use in web pages
Diagram Already default implementation provide ed by Applet class
Compile and Execute Compile: javac programname.java Execution: appletviewer programname.java Note: applet program can add in html File and execute on web browser
Display message on applet drawString method used It is method of graphics class and use in paint method Syntax: drawString (String message, int x, int y) Message: a string that to display x: Horizontal starting position y: Vertical Starting position
Sample program to display hello word import java.applet.*; // Package public class Abc extends Applet { Public void paint (Graphics g) { g.drawString( “Hello”, 100,100); } } /* <applet> // Html code <applet code=“ Abc” height=200 width=200> </applet> */
Methods of applet class resize () It use to resize size of appletviewer Syntax: resize( int width, int height ) e.g. resize ( 500, 600)
Methods of applet class setBackground () It use to set background color of appletviewer Syntax: setBackground( Color. colorname) e.g. setBackground( Color. red)
Methods of applet class setForeground () It use to set Foreground color of appletviewer Syntax: setForeground( Color. colorname) e.g. setForeground( Color. red)
Methods of applet class showStatus () It use to set status of status bar of appletviewer Syntax: showStatus( String message) e.g. showStatus( “ Welcome”)
Methods of applet class getCodeBase () It use to get path of Program where it stored without program name Syntax: getCodeBase( ) e.g. URL u= getCodeBase( ) u= C:\Program Files (x86)\Java\jdk1.7.0\bin
Methods of applet class getDocumentBase () It use to get path of Program where it stored along with program name. Syntax: getDocumentBase( ) e.g. URL u= getDocumentBase( ) u= C:\Program Files (x86)\Java\jdk1.7.0\bin\ac.java
Applet in html Applet tags: code: Program name width: width of page Height: height of page align: alignment hspace: horizontalspace vspace: verticalspace codebase: path of program
Param tag It use to accept input from user It has two attributes: name and value and both are in string format User can access value of parameter using getParameter method Syntax: String variablename= getParameter(String parametername) e.g. <param name=“font” value=“10”> String f= getParameter(“font”) f= 10
Font It is a class available in java.awt package syntax: Font objectname= new Font (String fontname, int fontstyle, int fontsize) Fontstyle: 0- Plain OR Font.PLAIN 1- Bold OR Font.BOLD 2- Italic OR Font.ITALIC 3- Bold+italic OR Font.BOLD+Font.ITALIC e. g Font f1 = new Font (“Arial”,2,24)
Set and Get Font setFont(): method of graphics class Syntax: Graphicsclassobject. setFont(FontObject) e.g g.setFont(f) getFont(): It gives information of the font which currently set Syntax: Graphicsclassobject. getFont() o/p: jawa.awt.Font(name=arial style=bold size=12)
Methods of font class getName(): it retunes name of font in string. getStyle(): it returns style of font in int getSize(): it returns size of font in int isPlain(): It returns Boolean value which check whatever style of font is plain or not isBold(): It returns Boolean value which check whatever style of font is Bold or not isItalic():It returns Boolean value which check whatever style of font is Italic or not
Color It is a class available in java.awt package syntax: Color objectname= new Color (int red, int green, int blue) Value of red, green and blue in between 0-255 e.g Color c1 = new Color (120,130,55)
Set and Get Color setColor(): method of graphics class Syntax: Graphicsclassobject. setColor(ColorObject) e.g g.setColor(c1) getColor(): It gives information of the Color which currently set Syntax: Graphicsclassobject. getColor() o/p: jawa.awt.Color (red= 120, green=130, blue=55)
Methods of Color class getRed(): it retunes value of red Color in integer. getGreen(): it retunes value of Green Color in integer. getBlue(): it retunes value of Blue Color in integer.
Methods of Graphics class drawLine (): it use to draw line on applet. Syntax: drawLine ( int x1,int y1, int x2,int y2) (x1,y1): first end of Line (x2,y2): Second end of line E.g drawLine (120,200,50,70)
Methods of Graphics class drawRect (): it use to draw rectangle on applet. Syntax: drawRect( int x1,int y1, int width, int height) (x1,y1): starting point of rectangle Width: width of rectangle Height: height of rectangle E.g drawRect (120,200,50,70)
Methods of Graphics class drawRoundRect (): it use to draw rectangle on applet. Syntax: drawRoundRect( int x1,int y1, int width, int height, int x diameter, int y diameter) (x1,y1): starting point of rectangle Width: width of rectangle Height: height of rectangle E.g drawRoundRect (120,200,50,70,20,30)
Methods of Graphics class drawOval (): it use to draw oval on applet. Syntax: drawOval( int x1,int y1, int width, int height) (x1,y1): starting point of rectangle Width: width of rectangle Height: height of rectangle E.g drawOval (120,200,50,70)
Methods of Graphics class drawArc (): it use to draw arc on applet. Syntax: drawArc( int x1,int y1, int width, int height, int startangle, int sweep angle) (x1,y1): starting point of rectangle Width: width of rectangle Height: height of rectangle Sweep angle: +ve: anticlockwise -ve: clockwise E.g drawArc (120,200,50,70,45,45)
Methods of Graphics class drawPolygon (): it use to draw polygon on applet. Syntax: drawPolygon( int x[ ], int y[ ], int nop) X[ ]: array of integer Y[ ]: array of integer Nop: number of points
Using graphics class Drawing line graph Drawing bar chart