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);
}
}