Differentiate between components and containers. Explain different AWT container briefly.

 The difference between components and containers are :- 

Components

At the top of the AWT, hierarchy is the Component class. The component is an abstract class that encapsulates all of the attributes of a component. All user interface elements that are displayed on the screen and that interact with the user are subclasses of Component. It defines over a hundred public methods that are responsible for managing events. The component object is responsible for remembering the current foreground and background colors, currently selected text font, and current text alignment.

Containers

The Container class is a subclass of Component. It has additional features that allow other Component objects to be placed within it. Other Container objects can also be stored inside of a Container since they are themselves instances of Component. Thus, allowing a multileveled containment system. A container is responsible for positioning any component placed on it. It does this through the use of various layout managers. The default layout is present in each. container which can be overridden using the setLayout method.

Different AWT container are described below:- 

                                          

Window
The Window class creates a top-level window. A top-level window is not contained within any other object. It sits directly on the desktop. Generally, we won't create objects of Window classes directly. Instead, we will use a subclass of Window called Frame or Dialog. It uses BorderLayout as the default layout manager.
Commonly used Constructors
Window (Frame owner):-Constructs a new, initially invisible window with the specified Frame as its owner
Window (Window owner):- Constructs a new, initially invisible window specified Window as its owner.
Window(Window owner, Graphics Configuration ge):- Constructs a new, initially invisible window with the specified owner Window and a GraphicsConfiguration of a screen device.

Frame
It is a sub-class of Window class that has a title bar, menu bar, borders and is re-sizable with border layout by default. This is what we use in our programs to create windows.
Commonly used Constructors
Frame(): Constructs a new instance of Frame that is initially invisible
Frame(String title):- Constructs a new, initially invisible Frame object with the specified title

  Dialog Boxes
The dialog box is a window with a title bar but with no minimize or maximize options. It is a direct subclass of Window and comes with default BorderLayout. An instance of the Dialog class cannot exist without an associated instance of the Frame class. It can be constructed with a parent, typically a Frame or another dialog. Dialogs are divided into types, Modal and Modeless (default). A modal dialog blocks user input of top-level windows of the dialog (i.e. its parents, but not its children) while a modeless dialog doesn't. 

Panel
The class Panel is the simplest container class. It provides space in which an application can attach any other component, including other panels. It uses FlowLayout as the default layout manager. It is a borderless window that doesn't contain any title bar or menubar. It is usually added to another container like the Frame. The main purpose of a panel is to group components.
Commonly used Constructors
Panel():- Creates a new panel using the default layout manager -Panel(LayoutManager layout):- Creates a new panel with the specified layout manager
Other components can be added to a Panel object by its add() method (inherited from Container). Once these components have been added, you can position and resize them defined by the Component.
manually using the setLocation(), setSize(), setPreferredSize(), or setBounds() methods




                                     OR,

 Containers: As the name suggests, this awt component is used to hold other components.

Basically, there are the following different types of containers available in java.awt package:

a. Window: This is a top-level container and an instance of a window class that does not contain a border or title.

b. Frame: Frame is a Window class child and comprises the title bar, border and menu bars. Therefore, the frame provides a resizable canvas and is the most widely used container used for developing AWT-based applications. Various components such as buttons, text fields, scrollbars etc., can be accommodated inside the frame container.

Java Frame can be created in two ways:

By Creating an object of Frame class.
By making Frame class parent of our class.
Dialog: Dialog is also a child class of window class, and it provides support for the border as well as the title bar. In order to use dialog as a container, it always needs an instance of frame class associated with it.
Panel: It is used for holding graphical user interface components and does not provide support for the title bar, border or menu.

                       OR,

Container

The Container is a component in AWT that can contain other components like buttons, text fields, labels, etc. The classes that extend the Container class are known as containers such as Frame, Dialog, and Panel.

It is basically a screen where the components are placed at their specific locations. Thus it contains and controls the layout of components.

There are four types of containers in Java AWT:

1) Window

2) Panel

3) Frame

4) Dialog


1) Window

The window is the container that has no borders and menu bars. You must use frame, dialog, or another window for creating a window. We need to create an instance of the Window class to create this container.

2) Panel

The Panel is the container that doesn't contain title bar, border or menu bar. It is generic container for holding the components. It can have other components like button, text field etc. An instance of Panel class creates a container, in which we can add components.

3) Frame

The Frame is the container that contains title bar and border and can have menu bars. It can have other components like buttons, text field, scrollbar etc. Frame is most widely used container while developing an AWT application.

                           

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?

Discuss classification or taxonomy of virtualization at different levels.