Discuss group layout with suitable example.

GroupLayout

GroupLayout groups its components and place them in a Container hierarchically. The grouping is done by instances of the Group class. Group is an abstract class, and two concrete classes which implement this Group class are SequentialGroup and ParallelGroup. SequentialGroup positions its child sequentially one after another whereas ParallelGroup aligns its child on top of each other. The GroupLayout class provides methods such as createParallelGroup() and createSequentialGroup() to create groups.

GroupLayout treats each axis independently. That is, there is a group representing the horizontal axis, and a group representing the vertical axis. Each component must exist in both a horizontal and vertical group, otherwise, an IllegalStateException is thrown during layout or when the minimum, preferred, or maximum size is requested.

Example:

import java.awt.*;

import javax.swing.*;

public class GroupExample {

public static void main(String[] args) {

JFrame frame = new JFrame("GroupLayoutExample");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Container contentPanel = frame.getContentPane();

GroupLayout groupLayout = new GroupLayout(contentPanel);

contentPanel.setLayout(groupLayout);

JLabel clickMe = new JLabel("Click Here");

JButton button = new JButton("This Button");

groupLayout.setHorizontalGroup(

groupLayout.createSequentialGroup()

.addComponent(clickMe)

.addGap(10, 20, 100)

.addComponent(button));

groupLayout.setVerticalGroup(

groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)

.addComponent(clickMe)

.addComponent(button));

frame.pack();

frame.setVisible(true);

}

}

                  OR,

GroupLayout is a layout manager that hierarchically groups components in order to position them in a Container. GroupLayout works with the horizontal and vertical layouts separately. The layout is defined for each dimension independently. We do not need to worry about the vertical dimension when defining the horizontal layout, and vice versa, as the layout along each axis is totally independent of the layout along the other axis. When focusing on just one dimension, we only have to solve half the problem at one time. This is easier than handling both dimensions at once. This means that each component needs to be defined twice in the layout. If we forget to do this, GroupLayout will generate an exception. The following program demonstrates using GroupLayout.

import javax.swing.*;

public class GroupLayoutTest extends JFrame {

public GroupLayoutTest() {

JPanel panel = new JPanel();

GroupLayout layout = new GroupLayout(panel);

JButton one = new JButton("Button 1");

JButton two = new JButton("Button 2");

JButton three = new JButton("Button 3");

JButton four = new JButton("Button 4");

JButton five = new JButton("Button 5");

JButton six = new JButton("Button 6");

layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addComponent(one)

.addComponent(two)

.addComponent(three)) //first group

.addGroup(layout.createSequentialGroup()

.addComponent(four)

.addComponent(five)) //second group

.addComponent(six));

layout.setVerticalGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)

.addComponent(one).addComponent(two).addComponent(three))

.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)

.addComponent(four).addComponent(five))

.addComponent(six));

panel.setLayout(layout);

add(panel);

setSize(400, 400);

setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main(String[] args) {

new GroupLayoutTest();

}

}



Comments

Popular posts from this blog

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 Parallel Efficiency of MapReduce.

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)?