AWT - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

AWT Toolkit

AWT Toolkit

shape Introduction

Basically, Java AWT is platform-independent. When using Java on other platforms, it should contain all the features required to support other platforms. So, to overcome this issue, JavaToolkit class is used to integrate the platform-independent classes and java.awt package such that its modules can be placed in the java.awt.peer package which consists of interfaces. The platform supporting Java should have a concrete class extending Toolkit class. AWT Toolkit chapter gives a clear idea about Toolkit and Peers.

Constructor

shape Description

Toolkit() : Basically toolkit is an abstract class and it does not have useful constructors. So, to have a toolkit object, one has to request for the default toolkit by using static method getDefaultToolkit().

Methods

shape Description

All these methods returns the modifications required.
Method Description
getScreenResolution() It returns the screen resolution in terms of dots.
getColorModel() It returns the colormodel of the system.
getFontList() It returns the font list being used on the Java platform.
getFontPeer It returns the requested peer interface to create the font.
getImage It returns an image which gets pixel data from the specified file
getPrintJob Returns the printobject to print
getProperty Returns the property as per the given key instruction.

shape Examples

[java]import java.awt.*; import java.awt.event.*; public class Splesson extends Frame { Image image; String Picture = "Splesson.jpg"; public Splesson () { 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 { Splesson image = new Splesson(); image.setTitle("Toolkit.getDefaultToolkit().getImage Example"); image.setSize(350,250); image.setVisible(true); image.setLocation(200,100); } } [/java] Output

Peer

shape Description

Implementing component in an environment is known as a peer. The connection between the peer and the component is called as peer interface. All these interfaces are stored in java.awt.peer package. ComponentPeer is the interface that is superior to all the non-menu objects and MenuComponentPeer is superior to all the menu objects.

shape Conceptual figure

Summary

shape Key Points

  • Toolkit is an abstract class.
  • Peer is the interface between the Toolkit and the working Java environment.