Lecture-3.1.2
Lecture-3.1.2
DEPARTMENT : CSE
Bachelor of Engineering (Computer Science & Engineering)
Java Programming (20CST-218)
TOPIC OF PRESENTATION:
2
Layout managers
The LayoutManagers are used to arrange components in a particular manner. LayoutManager is an
interface that is implemented by all the classes of layout managers.
There are following classes that represents the layout managers:
• java.awt.BorderLayout
• java.awt.FlowLayout
• java.awt.GridLayout
• java.awt.CardLayout
• java.awt.GridBagLayout
• javax.swing.BoxLayout
• javax.swing.GroupLayout
• javax.swing.ScrollPaneLayout
• javax.swing.SpringLayout etc.
Java BorderLayout
The BorderLayout is used to arrange the components in five regions: north, south,
east, west and center. Each region (area) may contain one component only. It is the
default layout of frame or window.
GridLayout(int rows, int columns): creates a grid layout with the given rows
and columns but no gaps between the components.
GridLayout(int rows, int columns, int hgap, int vgap): creates a grid layout
with the given rows and columns alongwith given horizontal and vertical gaps.
Example of GridLayout class
Java FlowLayout
The FlowLayout is used to arrange the components in a line, one after another (in a
flow). It is the default layout of applet or panel.
Button (java.awt.Button)
The two constructors are:
Button() // Constructs a Button with no label.
Button(String label) // Constructs a Button with the specified label.
12
AWT Components
Checkboxes (java.awt.Checkbox)
Checkboxes are two states, on and off. The state of the button is returned as the
Object argument, when a Checkbox event occurs. To find out the state of a
checkbox object we can use getState() that returns a true or false value. We can
also get the label of the checkbox using getLabel() that returns a String object.
13
AWT Components
Choice Buttons (java.awt.Choice)
Like a radio button, where we make a selection, however it requires less space and
allows us to add items to the menu dynamically using the addItem() method.
14
AWT Components
Labels (java.awt.Label)
Allow us to add a text description to a point on the applet or application.
TextFields (java.awt.TextField)
There are numerous ways that we can construct a Textfield object:
TextField text1 = new TextField(); // no properties
TextField text2 = new TextField("Some text"); // a textfield with a predefined String
TextField text3 = new TextField(40); // a textfield with a predefined size
TextField text4 = new TextField("Some text", 50); // combination of the two
15
MCQ
What pattern does the FlowLayout layout manager use to add components to a container?
16
Summary:
Video Lectures :
https://youtu.be/utouefZ6WpU
https://youtu.be/__fZuZeq620
Reference Links:
http://www.eeng.dcu.ie/~ee553/ee402notes/html/ch09s02.html
https://www.javatpoint.com/java-awt
https://www.javatpoint.com/java-layout-manager
THANK YOU