Lecture 16


Published on

Notes on core java

Published in: Technology, Education
  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Lecture 16

  1. 1. Core Java Debasish Pratihari LayoutManager :  LayoutManager determines the way components will be arranged inside the container.  All container’s have their default LayoutManger.  However You can apply a different LayoutManager to the containers if required.  LayoutManager Classes are Provided in java.awt and javax.swing package. FlowLayoutManager :  FlowLayout Manager lays down the components in a row and automatically spills components onto the next row if row is full.  The default positing of the components is centered in the container, and the default orientation is from left to right.  Constants to Control FlowLayoutManager: o LEFT o RIGHT o CENTER o LEADING TRAILING  Examples:  FlowLayout f= new FlowLayout();  FlowLayout f= new FlowLayout(FlowLayout.LEFT);  FlowLayout f= new FlowLayout(FlowLayout.LEFT,10,20); Lecture/core/awt4/16 Page #1 feel the Technology…
  2. 2. Core Java Debasish Pratihari BorderLayoutManager:  The BorderLayoutManager divides the container into file regions like o EAST o WEST o NORTH o SOUTH o CENTER.  Each region can accommodate only one component. Example : import java.awt.*; class BorderTest extends Frame{ Button b1,b2,b3,b4,b5; BorderTest(){ b1= new Button("EAST"); b2= new Button("WEST"); b3= new Button("NORTH"); b4= new Button("SOUTH"); b5=new Button("CENTER"); add(b1, BorderLayout.EAST); add(b2,BorderLayout.WEST); add(b3,BorderLayout.NORTH); add(b4,BorderLayout.SOUTH); add(b5,BorderLayout.CENTER); setTitle("BorderDemo By Debasish Pratihari"); setSize(200,200); setVisible(true); } public static void main(String args[]){ new BorderTest(); } } Lecture/core/awt4/16 Page #2 feel the Technology…
  3. 3. Core Java Debasish Pratihari CardLayout:  The CardLayout manager arrange the components in a stack, one on the top of another.  The first component will be at the top, so will be the only visible component.  Methods to operate CardLayout o void previous(Container parent) o void first (Container parent) o void last(Container parent) o void show(Container parent) Example : import java.awt.*; import java.awt.event.*; class CardTest extends Frame implements ActionListener{ Button b1,b2,b3,b4,b5; CardLayout card; CardTest(){ b1= new Button("JAVA"); b2= new Button("J2EE"); b3= new Button("C"); b4= new Button("C++"); b5=new Button("ORACLE"); card= new CardLayout(20,50); setLayout(card); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); b4.addActionListener(this); b5.addActionListener(this); add(b1,"card add(b2,"card add(b3,"card add(b4,"card add(b5,"card 1"); 2"); 3"); 4"); 5"); setTitle("BorderDemo By Debasish Pratihari"); setSize(200,200); setVisible(true); } public void actionPerformed(ActionEvent e){ card.next(this); } } public static void main(String args[]){ new CardTest(); } } Lecture/core/awt4/16 Page #3 feel the Technology…
  4. 4. Core Java Debasish Pratihari GridLayout:  A GridLayout manager arranges components in a rectangular grid within a container. Constructors:  GridLayout()  GridLayout(int rows, int cols)  GridLayout(int vgaps) rows,int cols, int hgaps, int Example : import java.awt.*; 25% Note : class GridTest extends Frame { GridTest(){ GridLayout layout= new GridLayout(3,3,10,10); setLayout(layout); for(int i=1;i<=9;i++) add(new Button("Button "+i)); If you want the window to assume the size that just accommodates the component it contains, use pack() setTitle("GridDemo By Debasish Pratihari"); setVisible(true); pack(); } public static void main(String ar[]){ new GridTest(); } } Output : Lecture/core/awt4/16 Page #4 feel the Technology…