- The java.awt.AWTEvent class is the highest-level class in the AWT event-class hierarchy.
- How can the answer be improved?
After having the basic idea of GUI, let us know how many Java AWT Components classes exist with java.awt package. This knowledge is essential to go further in the tutorial.As you can observe from the above hierarchy, Component is the super class of all Java components and is declared as abstract. That is, we cannot create objects of Component class directly.Following is the class signaturepublic abstract class Component extends Object implements ImageObserver, MenuContainer, Serializable Properties of Java AWT Components. A Component object represents a graphical interactive area displayable on the screen that can be used by the user. Any subclass of a Component class is known as a component.
For example, button is a component. Only components can be added to a container, like frame.Important methods of Component classFollowing are the important methods, practiced very often, of Component class that can be used by all the sub classes (components). setEnabled(boolean): The parameter false makes the component disabled so that it does not respond to user interactions (say, clicks).
The AWT package can be used by importing java.awt. as follows: import java.awt. The AWT has a set of Java classes that provide the standard set of user-interface elements (windows, menus, boxes, buttons, lists and so on). That is, AWT provides several facilities for drawing two-dimensional shapes, controlling colours and controlling fonts.
setBounds: Using this method, the programmer can give his own size to the component in terms of width and height and also the location where he can place the component in the container. This method is not used often as the programmer prefers to place the component in the container using layout managers. getWidth: The programmer can obtain the width of the component. getHeight: The programmer can obtain the height of the component. paint: Used very extensively to draw graphics. This method is called implicitly when the frame is created or resized. repaint: Used by the programmer to call the paint method explicitly anywhere in the program.
setBackground: Used to give a background color to a component. setForeground: Used to give a foreground color to a component.
The Class At The Top Of The Awt Hierarchy Is Called
setFont: Used to give a font to a component to display the text. getSize: Returns the size of the component. setSize: Used to give the size to the component. update: The is method is called implicitly by the repaint. A call to this method clears the earlier drawings existing on the container.
The Color class is a part of Java Abstract Window Toolkit(AWT) package. The Color class creates color by using the given RGBA values where RGBA stands for RED, GREEN, BLUE, ALPHA or using HSB value where HSB stands for HUE, SATURATION, BRIcomponents. The value for individual components RGBA ranges from 0 to 255 or 0.0 to 0.1.