What are layout managers? Explain Gridbag layout with suitable example.

  A layout manager  

A layout manager is an object that controls the size and position of the components in the container. Every container object has a layout manager object that controls its layout.

Actually, layout managers are used to arranging the components in a specific manner.  It is an interface that is implemented by all the classes of layout managers.  There are some classes that represent the layout managers.

 The LayoutManagers are used to arrange components in a particular manner. The Java LayoutManagers facilitate us to control the positioning and size of the components in GUI forms. LayoutManager is an interface that is implemented by all the classes of layout managers.

Some of the most commonly used layout managers of java are :

  • Flow Layout
  • Border Layout
  • Grid Layout
  • Gridbag layout
  • Card Layout
  • Group Layout

Gridbag layout

The Gridbag Layout is a flexible layout manager that aligns components vertically and horizontally, without requiring that the components be of the same size. It maintains a dynamic rectangular grid of cells, with each component occupying one or more cells. Each component managed by a grid bag layout is associated with an instance of Grid BagConstraints that specifies how the component is arranged within its display area.

Constructor

Grid BagLayout();//Creates a grid bag layout manager.

Example

import java.awt.*;

public class GridBagDemo extends Frame

{

Button b1,b2,b3, b4,b5;

Grid BagConstraints gbc;

GridBagDemo()

{

setSize(400,250);

setTitle("GridBag Layout Demo");

set Layout (new GridBagLayout());

gbc=new GridBagConstraints();

b1=new Button("Button 1");

gbc.ipadx = 8;

gbc.ipady = 0;

gbc.weightx=0.5;

gbc.weighty = 0.0;

gbc.fill=GridBagConstraints. HORIZONTAL; 

gbc.gridwidth = 1;

gbc.insets = new Insets (5,5,5,5);

gbc.gridx = 0; gbc.gridy = 0;

add (b1, gbc);

b2=new Button("Button 2");

gbc.gridx = 1;

add (b2, gbc);

b3=new Button("Button 3");

gbc.gridx 2;

add (b3, gbc);

b4=new Button("This is Long Button 4");

gbc.ipady=40;

gbc.gridwidth=3;

gbc.gridx = 0;

gbc.gridy = 1;

add (b4, gbc);

b5=new Button ("Button 5");

gbc.gridx=0;

gbc.gridy=2;

gbc.ipady=20;

gbc.gridwidth=2;

add (b5, gbc);

setVisible(true);

}

public static void main(String args[])

{

GridBagDemo frame=new Grid BagDemo ();

}

}


Comments

Popular posts from this blog

Suppose that a data warehouse for Big-University consists of the following four dimensions: student, course, semester, and instructor, and two measures count and avg_grade. When at the lowest conceptual level (e.g., for a given student, course, semester, and instructor combination), the avg_grade measure stores the actual course grade of the student. At higher conceptual levels, avg_grade stores the average grade for the given combination. a) Draw a snowflake schema diagram for the data warehouse. b) Starting with the base cuboid [student, course, semester, instructor], what specific OLAP operations (e.g., roll-up from semester to year) should one perform in order to list the average grade of CS courses for each BigUniversity student. c) If each dimension has five levels (including all), such as “student < major < status < university < all”, how many cuboids will this cube contain (including the base and apex cuboids)?

Suppose that a data warehouse consists of the four dimensions; date, spectator, location, and game, and the two measures, count and charge, where charge is the fee that a spectator pays when watching a game on a given date. Spectators may be students, adults, or seniors, with each category having its own charge rate. a) Draw a star schema diagram for the data b) Starting with the base cuboid [date; spectator; location; game], what specific OLAP operations should perform in order to list the total charge paid by student spectators at GM Place in 2004?

Explain market-Oriented Cloud computing architecture.