Featured Posts

[Travel][feat1]

All About INTERFACE LayoutManager in Java

October 23, 2018

A Container in java is a placeholder that contains different GUI attributes(like Frame,Panel,Label etc).Each container object has its own layout manager to place the child components on the screen.Each container object has a Layout manager which is an instance of any class that implements LayoutManager interface.Thus each component(Frame,Panel,Label etc) will have its default layout manager associated with it which may be changed by developer when an instance of that container is created.Each layout manager keeps track of its child components.The layout manager is notified each time one adds a component to the container.Java supports five different Layout Managers.They are as follows:

  1. FlowLayout
  2. BorderLayout
  3. GridLayout
  4. GridBagLayout
  5. CardLayout.
The interface LayoutManager specifies the methods that all the above layout manager must implement.A LayoutManager is responsible for laying out components of a container.

The interface structure of the LayoutManager is given as:

public interface java.awt.LayoutManager {
//methods
public abstract void addLayoutComponent(String name,Component comp);
public abstract void layoutContainer(Container target);
public abstract Dimension minimumLayoutSize(Container target);
public abstract Dimension preferredLayoutSize(Container target);
public abstract void removeLayoutComponent(Component comp);
} 
All About INTERFACE LayoutManager in Java All About INTERFACE LayoutManager in Java Reviewed by Animesh Chatterjee on October 23, 2018 Rating: 5

All About Class FlowLayout in AWT in Java

October 23, 2018
The most basic and default layout in java is FlowLayout. The manager implements a simple Layout style which is similar to how words flow in a text editor.Components are laid from upper left corner,left to right and top to bottom.When no more components fit on a line,the next one will appear in the next line.A small space is left between components,above and below.However user can change this gap,alignment etc.The default gap is five pixels and default alignment is center.Below are the different functions for FlowLayout.FlowLayout is typically used to arrange buttons in a panel.
The class structure of class FlowLayout is given as:


public class java.awt.FlowLayout extends java.lang.Object implements java.awt.LayoutManager{
//member elements
public final static int CENTER;
//this indicates that each row of components should be at center.
public final static int LEFT;
//this indicates that each row of components should be at left justified.
public final static int RIGHT;
//this indicates that each row of components should be at right justified.
//constructor
public FlowLayout();
public FlowLayout(int alignment);//alignment can be LEFT,CENTER,RIGHT
public FlowLayout(int alignment,int hgap,int vgap));//alignment can be LEFT,CENTER,RIGHT
//hgap and vgap are the space between two components horizontally and vertically.
//methods
public void addLayoutComponent(String name,Component comp);
public void layoutContainer(Container target);
}
 
public FlowLayout();
Creates a new FlowLayout manager with a centered alignment and a default 5 pixel horizontal and vertical gap.
public FlowLayout(int alignment);
Creates a new FlowLayout manager with a centered alignment and a default 5 pixel horizontal and vertical gap.The alignment argument must be FlowLayout.LEFT,FlowLayout.RIGHT,FlowLayout.CENTER
All About Class FlowLayout in AWT in Java All About Class FlowLayout in AWT in Java Reviewed by Animesh Chatterjee on October 23, 2018 Rating: 5

All About Class GridBagLayout in AWT in Java

October 23, 2018


This is an upgraded version of GridLayout.With this we can specify the width,height of the individual grids in a container.The GridBagLayout manager is a flexible layout manager which aligns components horizontally and vertically,without requiring the component to be of the same size.Each GridBagLayout manager uses a rectangular grid of cells,with each component occupying one or more cells(display area).Each component in a GridBagLayout is associated with a set of constraints contained within a GridBagConstraints,instance contained within a GridBagConstraints,instance that specifies how the component is to be laid out within it's display area.The manner in which the GridBagLayout manager places a set of components depends on each components constraints and it's minimum size as well as the preferred size of the component'c container.To use a GridBagLayout effectively,one or more components must have a customized GridBagConstraints objects created for it.
The class structure of GridBagLayout is given as:

public class java.awt.GridBagLayout extends java.lang.Object implements java.awt.LayoutManager{
//member elements 
protected final static int MAXGRIDSIZE;
//MAXGRIDSIZE is 128 the maximum number of grid position both horizontally and vertically that 
//can be laid out by GridBagLayout .
protected final static int MINSIZE;
//MINSIZE is 1.The smallest grid that can be laid out by GridBagLayout .
//constructor
public GridBagLayout();//creates a GridBagLayout manager
//methods
public void addLayoutComponent(String name,Component comp);
public GridBagConstraints getConstraints(Component comp);
protected GridBagConstraints lookupConstraints(Component comp);
public void layoutContainer(Container target);
public Dimension minimumLayoutSize(Container target);
public Dimension preferredLayoutSize(Container target);
public void removeLayoutComponent(Component comp);
public void setConstraints(Component comp,GridBagConstraints constraints)
public String toString();
}
 
All About Class GridBagLayout in AWT in Java All About Class GridBagLayout in AWT in Java Reviewed by Animesh Chatterjee on October 23, 2018 Rating: 5

All About Class GridLayout in AWT in Java

October 23, 2018


GridLayout provides flexibility for placing components.It causes container's component to be laid out in a rectangular grid.The container is split into equal sized rectangles.One component is placed into each rectangle.We can create the manager with a number of rows and columns.Components then fill up the calls defined by the manager.
The class structure of class GridLayout is given below:


public class java.awt.GridLayout extends java.lang.Object implements java.awt.LayoutManager{
//constructor
public GridLayout(int rows,int cols);
public GridLayout(int rows,int cols,int hgap,int vgap);
//methods
public void addLayoutComponent(String name,Component comp);
public void layoutContainer(Container target);
public Dimension minimumLayoutSize(Container target);
public Dimension preferredLayoutSize(Container target);
public void removeLayoutSize(Container target);
public String toString();
}
 
public GridLayout(int rows,int cols);
creates a grid layout with the specified number of rows and columns.All components in the layout are given equal size.One but not both of rows and columns can be zero,which means that any number of objects can be placed in a row or in a column.
public GridLayout(int rows,int cols,int hgap,int vgap);
creates a grid layout with the specified number of rows and columns.All components in the layout are given equal size.In addition the horizontal and vertical gaps are placed at the left and right edge and between each of the columns.The vertical gaps are placed at the top and bottom edge and between each rows.One but not both of rows and columns can be zero,which means that any number of objects can be placed in a row or in a column.

Example

Button b1,b2,b3,b4,b5,b6;
Frame frame=new Frame();
frame.setLayout(new GridLayout(3,2));//3 rows and 2 columns
b1=new Button("B1");
b2=new Button("B2");
b3=new Button("B3");
b4=new Button("B4");
b5=new Button("B5");
b6=new Button("B6");
frame.add(b1);frame.add(b2);frame.add(b3);
frame.add(b4);frame.add(b5);frame.add(b6);
 
All About Class GridLayout in AWT in Java All About Class GridLayout in AWT in Java Reviewed by Animesh Chatterjee on October 23, 2018 Rating: 5

All About Class Canvas in AWT in Java

October 23, 2018


A canvas component represents a blank rectangular area of the screen onto which the application can draw or form which the application can trap input events from the user.An application must sub class the canvas class in order to get useful functionality such as creating a custom components. The paint method must be overridden in order to perform custom graphics on the canvas.The mouse,keyboard and focus events that may occur over canvas can be understood or sensed.The below methods may be overridden in order to catch user events-

  • gotFocus()
  • lostFocus()
  • keyDown()
  • keyUp()
  • mouseEnter()
  • mouseExit()
  • mouseMove()
  • mouseDrag()
  • mouseDown()
  • mouseUp()
The structure of the Class Canvas is given as:

public class java.awt.Canvas extends java.awt.Component{
//constructor
public Canvas();
//Methods
public void addNotify();
public void paint(Graphics g);
}
 
All About Class Canvas in AWT in Java All About Class Canvas in AWT in Java Reviewed by Animesh Chatterjee on October 23, 2018 Rating: 5
Powered by Blogger.