by Dinesh Thakur Category: AWT and Applets

addWindowListener method is used to add the windowlistener interface to the window. WindowClosing is a predefined method of WindowListener interface present in java.awt package. exit is a predefined static method present in System class, used to terminate the currently running java. syntax-public static void exit (int status)


Toolkit class is abstract class present in java.awt package. It toolkit is predefined method present in Toolkit class. This method is used to create the object of Toolkit class. Syntax-public static Toolkit getDefaultToolkit ().

getImage is a predefined abstract method present in Toolkit class. Return type of this method is Image class object. Syntax-public abstract Image getImage (java.net. URL)

drawImage and drawString are abstract methods present in Graphics class. These methods are used to draw an image and string respectively. Syntax-public abstract boolean drawImage (Image image, int, int, java. awt. image.ImageObserver) public abstract void drawString (String s, int, int)
setSize is a predefined method present in Frame class , used to set the size of the frame. setVisible is a predefined method present in Frame class, used to make the frame visible. setLocation is a predefined method present in Frame class, used to set the frame at a particular position.

Here is the Java Example for getDefaultToolkitExample:

import java.awt.*;

import java.awt.event.*;
public class getDefaultToolkitExample extends Frame
{
              Image image;
              String Picture = "DineshThakur.jpg";
              public getDefaultToolkitExample ()
                   {
                       addWindowListener(new WindowAdapter()
                          {
                                public void windowClosing(WindowEvent we)
                                   {
                                        System.exit(0);
                                   }
                           });
                    }
                              public void paint(Graphics g)
                                 {
                                    Toolkit tool = Toolkit.getDefaultToolkit();
                                     image = tool.getImage(Picture);
                                     g.drawImage(image,145,110,this);
                                  
                                  }
                              public static void main(String args []) throws Exception
                                 {
                                          getDefaultToolkitExample image = new getDefaultToolkitExample();
                                          image.setTitle("Toolkit.getDefaultToolkit().getImage Example");
                                          image.setSize(350,250);
                                          image.setVisible(true);
                                          image.setLocation(200,100);
                                        
                                 }
}

Toolkit.getDefaultToolkit().getImage in Java Example

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content





Popular Article