TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Saturday, 11 April 2020

Dispaly Image In java In Applet

   Displaying Image in Applet

Applet is mostly used in games and animation. For this purpose image is required to be displayed. The java.awt.Graphics class provide a method drawImage() to display the image.

image in applet

Fig:Display Image In Applet

Syntax of drawImage() method:

public abstract boolean drawImage(Image img, int x,

 int y, ImageObserver observer): is used draw the specified image.

How to get the object of Image:

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:

1.    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.*;   
i   mport 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