Presentation is loading. Please wait.

Presentation is loading. Please wait.

Applets Applet is java program that can be embedded into HTML pages. Java applets runs on the java enabled web browsers such as mozilla and internet explorer.

Similar presentations


Presentation on theme: "Applets Applet is java program that can be embedded into HTML pages. Java applets runs on the java enabled web browsers such as mozilla and internet explorer."— Presentation transcript:

1

2 Applets Applet is java program that can be embedded into HTML pages. Java applets runs on the java enabled web browsers such as mozilla and internet explorer. Applet can't access system resources on the local computer. Applets are used to make the web site more dynamic and entertaining.

3 Jdk provides us with a special tool called AppletViewer. Applet class is defined in java.applet package. Applet execution doesnot begin at main. Applet appear within a Html page & contain GUI controls like buttons,list,boxes etc. When user interacts with these controls an event is genetated.

4

5 init(): This method is called to initialized an applet. start() : This method is called after the initialization of the applet.It is called when user returns to the HTMl page. stop(): This method can be called multiple times in the life cycle of an Applet moves out of the HTMl page. destroy(): This method is called only once in the life cycle of the applet when applet is unloaded from the memory. paint():it is called each time applets o/p is drawn

6 public void paint(Graphics g){ This method is drawing method. This method draws anything that is in the applet,to the screen. An instance(g) of the Class Graphics is passed to it. It takes a String and an x and a y coordinate as it’s argument.

7 The repaint() Method The repaint() method is the one invoked by a program to do drawing. repaint() ==> update() ==> paint() repaint() does not invoke paint() directly. It schedules a call to an intermediate method, update(). Finally, update() calls paint(). update() Clears screen Sets back & foreground colors Invokes paint() method

8 public void showStatus(String msg) Outputs a message string in the "status window". URL getDocumentBase() Returns the URL of the HTML file in which the applet is embedded. URL getCodeBase() Returns the URL of the class file that contains applet.

9 The java.awt package “awt” stands for “Abstract Window Toolkit” The java.awt package includes classes for: Drawing lines and shapes Drawing letters Setting colors Choosing fonts If it’s drawn on the screen, then java.awt is probably involved.

10 Java’s coordinate system Java uses an (x, y) coordinate system (0, 0) is the top left corner (50, 0) is 50 pixels to the right of (0, 0) (0, 20) is 20 pixels down from (0, 0) (w - 1, h - 1) is just inside the bottom right corner, where w is the width of the window and h is its height (0, 0) (0, 20) (50, 0) (50, 20) (w-1, h-1)

11 The Graphics class contains drawing methods drawLine(x1,y1,x2,y2) g.drawLine(100,100,420,312); drawRect(x,y,width,height); g.drawRect(72,160,200,35); drawOval (x, y, width, height) g.drawOval(300,120,100,75);

12 drawArc (int x, int y, int width, int height, int startAngle, int arcAngle) drawArc(100,100,80,60,45,120); Draws the outline of a circular or elliptical arc covering the specified rectangle. fillArc() Fills a circular or elliptical arc covering the specified rectangle drawPolyline (int[] xPoints, int[] yPoints, int nPoints)

13 fillPolygon(int[], int[], int points), drawPolyline(int[], int[], int points): Draws a closed polygon defined by arrays of x and y coordinates draw3DRect(x,y,width,height,boolean raised): Draws a 3-D highlighted outline of the specified rectangle. The edges of the rectangle are highlighted so that they appear to be beveled and lit from the upper left corner.

14 g.drawLine( x1, y1, x2, y2 ); g.drawOval( left, top, width, height ); g.fillOval( left, top, width, height ); g.drawRoundRect( left, top, width, height ); g.fillRoundRect( left, top, width, height ); g.drawArc( left, top, width, height, startAngle, arcAngle ); g.drawString( string, x, y );

15 Colors: To use a color, g.setColor(Color.RED); The java.awt package defines a class named Color There are 13 predefined Color.BLACK Color.PINK Color.GREEN Color.RED Color.DARK_GRAY Color.CYAN Color.GRAYColor.ORANGE Color.BLUE Color.LIGHT_GRAY Color.YELLOW Color.WHITE Color.MAGENTA Every color is a mix of red, green, and blue To make your own colors: Amounts range from 0 to 255 new Color( red, green, blue ) Black is (0, 0, 0), white is (255, 255, 255)

16 setBackground (Color c)-sets background color; setForeground (Color c)-sets foreground color; Color getBackground();gets Background color; Color getForeground(); gets Foreground color;

17 Font (String name, int style, int size) Creates a new Font from the specified name, style and point size. PLAIN:0 BOLD:1 ITALIC:2 To create a FontMetrics object, where g is a Graphics object and f is a Font object: FontMetrics fm = g.getFontMetrics(f);

18 int getAscent() Determines the font ascent of the Font described by this FontMetrics object. Int getDescent() Determines the font descent of the Font described by this FontMetrics object. Font getFont() Gets the Font described by this FontMetrics object. intgetHeight() Gets the standard height of a line of text in this font. int getLeading() Determines the standard leading of the Font described by this FontMetrics object


Download ppt "Applets Applet is java program that can be embedded into HTML pages. Java applets runs on the java enabled web browsers such as mozilla and internet explorer."

Similar presentations


Ads by Google