Java AWT
ava AWT Hierarchy
Container
Window
Panel
Frame
Useful Methods of Component class
Method | Description |
---|---|
public void add(Component c) | inserts a component on this component. |
public void setSize(int width,int height) | sets the size (width and height) of the component. |
public void setLayout(LayoutManager m) | defines the layout manager for the component. |
public void setVisible(boolean status) | changes the visibility of the component, by default false. |
1)setBounds()
The setBounds() method needs four arguments. The first two arguments are x and y coordinates of the top-left corner of the component, the third argument is the width of the component and the fourth argument is the height of the component.
Syntax:-
setBounds(int x-coordinate, int y-coordinate, int width, int height)
2)setSize ()
syntax:-
public void setSize(int width,
int height)
Sets the size of this Dimension object to the specified width and height. This method is included for completeness, to parallel the setSize method defined by Component.
Parameters:
width - the new width for this Dimension object
height - the new height for this Dimension object
3)Java LayoutManagers :-
The LayoutManagers are used to arrange components in a particular manner. The Java LayoutManagers facilitates us to control the positioning and size of the components in GUI forms. LayoutManager is an interface that is implemented by all the classes of layout managers. There are the following classes that represent the layout managers:
java.awt.BorderLayout
java.awt.FlowLayout
java.awt.GridLayout
4)The setVisible(true) method makes the frame appear on the screen. If you forget to do this, the frame object will exist as an object in memory, but no picture will appear on the screen. Later on in a program, if you call setVisible(false) the frame will become invisible, but the software object will still exist and can be made visible again with setVisible(true).
5)The add() method of Set in Java is used to add a specific element into a Set collection. The function adds the element only if the specified element is not already present in the set else the function return False if the element is already present in the Set.
Java AWT Example
- By extending Frame class (inheritance)
- By creating the object of Frame class (association)
AWT Example by Inheritance
AWT Example by Association
Sign up here with your email
ConversionConversion EmoticonEmoticon