Abstract Class Toolkit in Java

0
64
Spread the love
  • 23
  • 34
  • 56
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    160
    Shares

Abstract Class Toolkit in Java

Toolkit abstract class defines methods that, when implemented, create platform-dependent “peers” for each of the java.awt.Component types. Java supports its platform-independent GUI interface by implementing a subclass of Toolkit for each platform.

Portable programs should never use these methods to create peers directly, rather they should use the Component classes themselves. A Toolkit object cannot be instantiated directly. Component.getToolkit() returns the Toolkit being used for a particular component.

The Toolkit class defines a few methods that you can use directly, the static method getDefaultToolkit() returns the default Toolkit that is in use. getScreensize() returns the screen size in pixels, and getScreenResolution() returns the resolution in dots – per – inch. getFontList() returns the names of supported fonts, sync() flushes all pending graphics output, which can be useful for animation.

The abstract Toolkit class provides access to platform-specific details like window size and available fonts. It also deals with creating all the components’ peer objects when you call addNotify().

The Class Structure of the Toolkit is given as

public abstract class java.awt.Toolkit extends java.lang.Object{
// Default Constructor:
public Toolkit()
// Class Methods
public static synchronized Toolkit getDefaultToolkit();
protected static Container getNativeContainer(Component c);
public static String getProperty(String key, String defaultValue);
// Public Instance Methods
public abstract void beep();
public abstract int checkImage(Image image, int width, int height,ImageObserver observer);
public abstract Image createImage(ImageProducer producer);
public Image createImage(byte [ ] imagedata);
public abstract Image createImage(byte [ ] imagedata, int imageoffset, int imagelength); 
public abstract ColorModel getColorModel();
public abstract String [ ] getFontList();
public abstract FontMetrics getFontMetrics(Font font);
public abstract Image getImage(String filename);
public abstract Image getImage(URL url);
public int getMenuShortcutKeyMask();
public abstract PrintJob getPrintJob(Frame frame, String jobtitle,Properties props); 
public abstract int getScreenResolution();
public abstract Dimension getScreensize();
public abstract Clipboard getSystemClipboard();
public final EventQueue getSystemEventQueue();
public abstract boolean prepareImage(Image image, int width, int height,ImageObserver observer);
public abstract void sync ();
// Protected Instance Methods
protected abstract ButtonPeer createButton(Button target);
protected abstract CanvasPeer createCanvas(Canvas target);
protected abstract CheckboxPeer createCheckbox(Checkbox target);
protected abstract CheckboxMenuItemPeer createCheckboxMenuItem (CheckboxMenuItem target);
protected abstract ChoicePeer createChoice(Choice target);
protected LightweightPeer createComponent(Component target);
protected abstract DialogPeer createDialog(Dialog target);
protected abstract FileDialogPeer createFileDialog(FileDialog target);
protected abstract FramePeer createFrame(Frame target);
protected abstract LabelPeer createLabel(Label target);
protected abstract ListPeer createList(List target);
protected abstract MenuPeer createMenu(Menu target);
protected abstract MenuBarPeer createMenuBar(MenuBar target)
protected abstract MenuItemPeer createMenuItem(MenuItem target);
protected abstract PanelPeer createPanel (Panel target);
protected abstract PopupMenuPeer createPopupMenu(PopupMenu target);
protected abstract ScrollPanePeer createScrollpane(Scrollpane target);
protected abstract ScrollbarPeer createScrollbar(Scrollbar target);
protected abstract TextAreaPeer createTextArea(TextArea target);
protected abstract TextFieldPeer createTextField(TextField target);
protected abstract WindowPeer createWindow(Window target);
protected abstract FontPeer getFontPeer(String name, int style);
protected abstract EventQueue getSystemEventQueueImpl();
protected void loadSystemColors (int [ ] systemColors);
}

The details of the class structure are given as follows:

public static synchronized Toolkit getDefaultToolkit();

public static synchronized Toolkit getDefaultToolkit() method returns the system’s default Toolkit.

This method returns the system’s default Toolkit.

protected static Container getNativeContainer(Component c);

protected static Container getNativeContainer(Component c) method returns the native container for the given component. The component’s immediate parent may be a lightweight component.

This method returns the native container for the given component. The component’s immediate parent may be a lightweight component.

public static String getProperty(String key, String defaultValue);

public static String getProperty(String key, String defaultValue) method returns the value of the property described by key, or defaultValue if it is not found.

This method returns the value of the property described by key, or defaultValue if it is not found.

Parameter
key – The name of a property.
defaultValue – A default value to return if the property is not found.

public abstract void beep();

public abstract void beep() method produces an audible beep.

public abstract int checkImage(Image image, int width, int height, ImageObserver observer);

public abstract int checkImage(Image image, int width, int height, ImageObserver observer) method checks on the status of the construction of a screen representation of image on observer.

This method returns the ImageObserver flags ORed together for the data that is now available.

Parameter
image – Image to check.
width – Width of the scaled image; -1 if image will be rendered unscaled.
height – Height of the scaled image; -1 if image will be rendered unscaled.
observer – The Component that image will be rendered on.

public abstract Image createImage(ImageProducer producer);

public abstract Image createImage(ImageProducer producer) method creates a new Image from an ImageProducer.

This method returns the newly created Image.

Parameter
producer – An ImageProducer that generates data for the desired image.

public Image createImage(byte[] imagedata);

public Image createImage(byte[] imagedata) method creates a new Image from the imagedata provided.

This method returns the newly created Image.

Parameter
imagedata – Raw data representing an image.

public abstract Image createImage(byte[ ] imagedata, int imageoffset, int imagelength);

public abstract Image createImage(byte[ ] imagedata, int imageoffset, int imagelength) method creates a new Image from the imagedata provided, starting at imageoffset bytes and reading imagelength bytes.

This method returns the newly created Image.

Parameter
imagedata – Raw data representing one or more images.
imageoffset – An offset into the data given.
imagelength – The length of data to use.

public abstract ColorModel getColorModel();

public abstract ColorModel getColorModel() method returns the current ColorModel used by the system.

This method returns the current ColorModel used by the system.

public abstract String[] getFontList();

public abstract String[] getFontList() method returns a String array of the set of Java fonts available with this Toolkit.

This method returns a String array of the set of Java fonts available with this Toolkit.

public abstract FontMetrics getFontMetrics(Font font);

public abstract FontMetrics getFontMetrics(Font font) method returns the current FontMetrics for the font on the user’s system.

This method returns the current FontMetrics for the font on the user’s system.

Parameter
font – A Font whose metrics are desired

public abstract Image getImage(String filename);

public abstract Image getImage(String filename) method fetches an image from the local file system.

This method returns the Image that needs to be fetched.

Parameter
filename – Location of Image on local filesystem

public abstract Image getImage(URL url);

public abstract Image getImage(URL url) method fetches an image from a URL.

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 23
  • 34
  • 56
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    160
    Shares

LEAVE A REPLY

Please enter your comment!
Please enter your name here