The java.applet.Applet class provides getImage() method that returns the object of Image. Syntax:
- public Image getImage(URL u, String image){}
Other required methods of Applet class to display image:
- public URL getDocumentBase(): is used to return the URL of the document in which
applet is embedded. 2. public URL getCodeBase(): is used to return the base URL.
Example of displaying image in applet:
- import java.awt.*;
- import java.applet.*;
-
-
- public class DisplayImage extends Applet {
-
- Image picture;
-
- public void init() {
- picture = getImage(getDocumentBase(),"sonoo.jpg");
- }
-
- public void paint(Graphics g) {
- g.drawImage(picture, 30,30, this);
- }
-
- }
myapplet.html
- <html>
- <body>
- <applet code="DisplayImage.class" width="300" height="300">
- </applet>
- </body>
- </html>
|
|
No comments:
Post a Comment