Abstract Windows Toolkit for Computer Science and MCA students

Write a note on Event Delegation Model.

  • The event model is based on the Event Source and Event Listeners.
  • Event Listener is an object that receives the messages / events. The Event Source is any object which creates the message / event.
  • The Event Delegation model is based on - The Event Classes, The Event Listeners, Event Objects.
  • There are three participants in event delegation model in Java:

    1. Event Source : the class which broadcasts the events.
    2. Event Listeners : the classes which receive notifications of events.
    3. Event Object : the class object which describes the event.
  • An event occurs (like mouse click, key press, etc) which is followed by the event is broadcasted by the event source by invoking an agreed method on all event listeners.
  • The event object is passed as argument to the agreed-upon method. Later the event listeners respond as they fit, like submit a form, displaying a message / alert etc.
Advantages
  • Event-delegation model allows a separation between a component's design and its use as it enables event handling to be handled by objects other than the ones that generate the events.
  • As event-delegation model does not have to repeatedly process unhandled events, it performs much better in applications where many events are generated. This is unlike the event inheritance model.

Write a note on Layout Managers.

  • A layout manager organizes the objects in a container.
  • Layout manager is an object that is used to implement an interface which determines the size and position of the component that is used inside a container.
  • Components can provide the size and the alignments regarding the container's layout.
The main layouts that are used in the layout managers are given as:

1. Border Layout
  • It has five areas for holding components: north, east, west, south and center.
  • When there are only 5 elements to be placed, border layout is the right choice.
2. Flow Layout
  • Default layout manager.
  • It lays out the components from left to right.
3. Card Layout
  • Different components at different times are laid out.
  • Controlled by a combo box, determining which panel the Card layout displays.
4. Grid Layout
  • A group of components are laid out I equal size and displays them in certain rows and columns.
5. Grid Bag Layout
  • Flexible layout for placing components within a grid of cells
  • Allows certain components to span more than one cell.
  • The rows of the grid are not of the same height and height.