Friday, 14 March 2014

LAYOUT MANAGERS:FlowLayout

FlowLayout places component in rows from left to right. Components towards the end of row are written on next row............

FlowLayout

FlowLayout places component in rows from left to right. Components towards the end of row are written on next row, if there is not enough space in the current row. The FlowLayout honors the specified size of a component. The size of a component never changes regardless of size of container.

 constructors of FlowLayout


Typically the constructor is called in the call to the container's setLayout method (see example code). The parameterless FlowLayout() constructor is probably most common, but there are some good places to use the alignment.

  • FlowLayout();
  • FlowLayout(int alignment);
  • FlowLayout(int alignment, int hor_gap, int ver_gap);

Alignment can take values of constants - LEFT, CENTER and RIGHT. The default alignment for the components in a row is center. Default horizontal and vertical gaps are 5 pixels.


  • FlowLayout.LEFT
  • FlowLayout.CENTER
  • FlowLayout.RIGHT

LAYOUT MANAGERS:BorderLayout

The class BorderLayout arranges the components to fit in the five regions: east, west, north, south and center. 

Border Layout

The class BorderLayout arranges the components to fit in the five regions: east, west, north, south and center. Each region is can contain only one component and each component in each region is identified by the corresponding constant NORTH, SOUTH, EAST, WEST, and CENTER.

constructors


  • BorderLayout():Constructs a new border layout with no gaps between components.

  • BorderLayout(int hgap, int vgap):Constructs a border layout with the specified gaps between components.

Thursday, 13 March 2014

LAYOUT MANAGERS

A Layoutmanager automatically arrange your controls within a window by using some type of algorithm.Java technology uses Layout Managers to define the location and size of Graphical User Interface components.


UNDERSTANDING LAYOUT MANAGERS:



A Layoutmanager automatically arrange your controls within a window by using some type of algorithm.Java technology uses Layout Managers to define the location and size of Graphical User Interface components. Java technology does not encourage programmers to use absolute location and size of components. Java technology instead places components based on specified Layout Manager. 

          A Layout Manager implements a layout policy that defines constraints between components in a container.Create a new layout object (using one of its constructors) and use the container's setLayout method to set the layout. Each layout has its own way to resize components to fit the layout, and you must become familiar with these.A layout manager is an object that implements the LayoutManager interface* and determines the size and position of the components within a container. Although components can provide size and alignment hints, a container's layout manager has the final say on the size and position of the components within the container.

Basic Layout Managers


  • FlowLayout:

Default for java.applet.Applet, java.awt.Panel and java.swing.JPanel. Places components sequentially (left to right) in the order they were added. You can specify the order.

FileDialog Box

Actually, you have already written code to open a file. ......

Open FileDialog Box

Actually, you have already written code to open a file. The process is no different for the open file dialogue box. And because you have already written the classes that open and write to a file, you can just import them into the current project.To import a class that you have already written, have a look at the Properties window on the left of NetBeans. (If you can't see the properties window, click the Window menu item at the top of NetBeans. From the Window menu, select Properties.)

Expand the entry for your current project, and right-click the Libraries item:

Wednesday, 12 March 2014

MENUS

Java's Abstract Windowing Toolkit (AWT) includes four concrete menu classes: Menu, MenuItem ,MenuBar ,CheckboxMenuItem......

MENU BARS AND MENUS


Java's Abstract Windowing Toolkit (AWT) includes four concrete menu classes: menu bars representing a group of menus that appears across the top of the window or the screen (class MenuBar); pull-down menus that pull from menu bars or from other menus (class Menu); menu items that represent menu selections (class MenuItem); and menu items that the user can turn on and off (class CheckBoxMenuItem).
                  These classes are all subclasses of MenuComponent, not subclasses of Component. Because they aren't components, they can't be placed in any container -- the way you would place buttons and lists in a container. In a graphical user interface (GUI) the only way to use these menu classes is to place a menu bar (which can contain additional menus) in a frame using the frame's setMenuBar method. Since the applet class is not a subclass of Frame, it does not inherit the setMenuBar method. 

This means you cannot simply place a menu bar in an applet.


The main advantages of using AWT menus in applets rather than using a custom pop-up-menu class are:

Tuesday, 11 March 2014

LAYOUT MANAGERS:CardLayout

A CardLayout object is a layout manager for a container. It treats each component in the container as a card.......

CardLayout


A CardLayout object is a layout manager for a container. It treats each component in the container as a card. Only one card is visible at a time, and the container acts as a stack of cards. The first component added to a CardLayout object is the visible component when the container is first displayed. The ordering of cards is determined by the container's own internal ordering of its component objects. CardLayout defines a set of methods that allow an application to flip through these cards sequentially, or to show a specified card. The addLayoutComponent(java.awt.Component, java.lang.Object) method can be used to associate a string identifier with a given card for fast random access.

CardLayout provides these two constructors


  • CardLayout():Creates a new card layout with gaps of size zero.
  • CardLayout(int hgap, int vgap):Creates a new card layout with the specified horizontal and vertical gaps.

LAYOUT MANAGERS:GridLayout

A GridLayout places components in a grid of cells


GridLayout

GridLayout lays out components in a two dimensional grid.When you instantiate a gridLayout ,you define the number of rows and columns.A GridLayout places components in a grid of cells.Each component takes all the available space within its cell.Each cell is exactly the same size.Components are added to the layout from left to right, top to bottom.

The constructers supported by the GridLayout are shown here


  • GridLayout():create a single_column grid layout
  • GridLayout(int rows, int columns):Creates a grid layout with the specified number of rows and columns.
  •  GridLayout(int rows, int columns, int horizontalGap, int verticalGap):To specify the horizontal and vertical space left between components in horzontalGap and verticalGap