Download presentation
Presentation is loading. Please wait.
Published byAnne Golden Modified over 9 years ago
1
User-defined parameters can be passed to an applet using the tags.
2
Hello World
3
import java.awt.*; import java.applet.*; public class ParamTest extends Applet { String str; public void init() { str=getParameter("String"); setBackground(Color.yellow); setForeground(Color.red); } public void paint(Graphics g) { super.paint(g); g.drawString(str,20,20); }
4
The signature of the method getDocumentBase() defined by Applet class is: public URL getDocumentBase() The method getDocumentBase() gets the URL of the document in which this applet is embedded. For example, suppose an applet is contained within the document: http://java.sun.com.products/jdk/1.5/index.html The document base is: http://java.sun.com.products/jdk/1.5/index.html
5
The signature of the getCodeBase method is ◦ public URL getCodeBase() The method gets the base URL. This is the URL of the directory which contains this applet
6
/* */ import java.awt.*; import java.applet.*; import java.net.*; Public class URLDemo extends Applet { publicvoid paint(Graphics g){ String msg; URL url=getCodeBase(); msg = "Code Base : "+url.toString(); g.drawString(msg,10,20); url=getDocumentBase(); msg="Document Base : "+url.toString(); g.drawString(msg,10,40); }
7
Defined in the Applet Context interface. showDocument(URL) – Displays the document represented by the URL showDocument(URL,where) Displays the document represented by the URL at the location specified by where
8
Applet Context is an interface that is defined in the java.applet package. It is used by an applet to obtain information from the applet's environment through its methods. Using methods of this interface, we can transfer control to another document.
9
Rich class of graphics methods defined in the awt package. Can be drawn relative to a window. The origin of each window is at the top-left corner and is 0,0. Coordinates are specified in pixels.
10
MethodsDescription drawLine(int sX, int sY, int eX, int sY) Draw a line from (sX, sY) to (eX, eY) void drawRect(int top, int left, int width, int height) Draws a rectancle void drawOval(int top, int left, int width, int height) Draw an oval inside a rectangle whose dimensions are given void drawPolygon(int x[ ], int y[ ], int numPoints) Draws a polygon whose points are defined by the arrays of x and y. total no. of points given by numPoints
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.