1 / 29

Applet

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

Télécharger la présentation

Applet

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. Applet VS Application

  3. Life cycle (methods)

  4. Diagram Already default implementation provide ed by Applet class

  5. Compile and Execute Compile: javac programname.java Execution: appletviewer programname.java Note: applet program can add in html File and execute on web browser

  6. 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

  7. 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> */

  8. Methods of applet class resize () It use to resize size of appletviewer Syntax: resize( int width, int height ) e.g. resize ( 500, 600)

  9. Methods of applet class setBackground () It use to set background color of appletviewer Syntax: setBackground( Color. colorname) e.g. setBackground( Color. red)

  10. Methods of applet class setForeground () It use to set Foreground color of appletviewer Syntax: setForeground( Color. colorname) e.g. setForeground( Color. red)

  11. Methods of applet class showStatus () It use to set status of status bar of appletviewer Syntax: showStatus( String message) e.g. showStatus( “ Welcome”)

  12. 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

  13. 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

  14. 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

  15. 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

  16. 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)

  17. 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)

  18. 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

  19. 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)

  20. 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)

  21. 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.

  22. 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)

  23. 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)

  24. 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)

  25. 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)

  26. 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)

  27. 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

  28. Using graphics class Drawing line graph Drawing bar chart

More Related