Presentation is loading. Please wait.

Presentation is loading. Please wait.

LAB SESSION 10 *LAYOUT MANAGER *LISTENERS. Laying the components manually by using a null layout is tedious. Each container object has a layout manager.

Similar presentations


Presentation on theme: "LAB SESSION 10 *LAYOUT MANAGER *LISTENERS. Laying the components manually by using a null layout is tedious. Each container object has a layout manager."— Presentation transcript:

1 LAB SESSION 10 *LAYOUT MANAGER *LISTENERS

2 Laying the components manually by using a null layout is tedious. Each container object has a layout manager associated with it. The layout manager for the object is set using the method set Layout() method If no set Layout() method is called then default layout is set

3 Syntax void setLayout(LayoutManager x); There are 4 types of Layouts o FlowLayout o BorderLayout o GridLayout o CardLayout

4 FlowLayout This is the default Layout managers set to container object if its Layout is not set. It has a simple Layout style which is similar to how words flow in a text editor. Components are laid from the upper-left corner,left to right and top to bottom

5 Constructors for FLOWLAYOUT  FlowLayout()  FlowLayout(int how)  FlowLayout(int how,int horz,int vert) The first form creates the default layout which centers the components and leaves 5 pixels of space between components

6 The second form lets u specify how each line is aligned. Valid values of how are FlowLayout.LEFT FlowLayout.CENTER FlowLayout.RIGHT

7 BORDERLAYOUT It has four narrow,fixed width components at the edges and one large area in the center. The four sides are reffered to as north,west,south,east. The middle area is called as center. The constructors are BorderLayout() BorderLayout(int horz,int vert)

8 The constructors are BorderLayout() BorderLayout(int horz,int vert) o The first one is default borderLayout. o The second form is used to specify the horizontal and vertical space left between components in horz and vertical.

9 BorderLayout specifies some constants BorderLayout.CENTER BorderLayout.EAST BorderLayout.NORTH BorderLayout.SOUTH BorderLayout.WEST

10 We can add components to BorderLayout By using the method add() Void add(Component comp,Object region); Component specifies component to be added Region specifies the region the component is to be added LEFT,RIGHT,CENTER,EAST,or WEST

11 GridLayout lays out components in a two dimensional grid.When you instantiate a gridlayout,you define the number of rows and columns. GridLayout() GridLayout(int numrows,int Columns) GridLayout(int numrows,int Columns,int horz,int vert)

12 The first form creates a single column grid layout. The second form creates a grid Layout with the specified number of columns and rows The third form is used to specify the horizontal and vertical space left between components in horz and vertical

13 t Grid layout Flow Layout

14 center north eastwest south Border layout

15 Eg of grid Layout public class demo extends JApplet { Static final int n=4; Public void init() { setLayout(new GridLayout(n,n); For(i=0;i<n; i++){ For(j=0;j<n; j++){ Int k=i*n+j; If (k>0) Add(new Button(“ “+k)); }

16 Eg for border layout public class demo extends JApplet { Static final int n=4; Public void init() { setLayout(new BorderLayoutt()); Add(new Button (“north”, BorderLayout.NORTH)); Add(new Button (“south”, BorderLayout.SOUTH)); Add(new Button (“west”, BorderLayout.WEST)); Add(new Button (“east”, BorderLayout.EAST)); String msg= “adhagfhagfhg hfdgahfgfgahgf adjfhsafj”; Add(new TextArea (msg, BorderLayout.CENTER)); }


Download ppt "LAB SESSION 10 *LAYOUT MANAGER *LISTENERS. Laying the components manually by using a null layout is tedious. Each container object has a layout manager."

Similar presentations


Ads by Google