Saturday, 15 April 2017

Various event classes and their description


  • ActionEvent - It is generated when a button is pressed, a list item is double clicked or a menu item is selected.
  • ItemEvent - It is generated when checkbox, list item is clicked or when checkable menu item is selected or de-selected or even occurs when choice selection is made.
  • FocusEvent - It is generated when a component gains or looses the focus.
  • WindowEvent - It is generated when a window is activated, deactivate, opened, closed, closing, iconified, de-iconified.
  • MouseEvent - It is generated when a mouse is clicked, pressed, realesed, entered, exited.
  • MouseWheelEvent - It's generated when mouse wheel is moved.
  • KeyEvent - It is generated when a key pressed on the keyboard.
  • TextEvent - It is generated when the text value is changed in the textfield or textarea.
  • ContainerEvent - It is generated when a component is added oor removed from the container.]
  • ComponentEvent - It is generated when a component is resized, moved, hidden from a container.  
  • AdjustmentEvent - It is generated when scrollbar is manipulated.

Various abstract methods in Listeners interface

  • ActionLisener

  1. public void actionPerformed(ActionEvent ae) 
  • ItemListener

  1. public void itemStateChanged(ItemEvent ie)
  • WindowListener
  1. public void  windowClosed(WindowEvent we)
  2. public void windowOpened(WinowEvent we)
  3. public void windowActivated(WindowEvent we)
  4. public void windowDeactivated(WindowEvent we)
  5. public void windwIconified(WindowEvent we)
  6. public void windowDeiconified WindowEvent we)
  • WindowFocusListener
  1. public void windowGainedFocus(WindowEvent we)
  2. public void windowLostFocus(WindowEvent we)
  • FocusListener

  1. public void focusGained(FocusEvent fe)
  2. public void focusLost(FocusEvent fe)
  • MouseListener
  1. public void mouseClicked(MouseEvent me)
  2. public void mousePressed(MouseEvent me)
  3. public void mouseReleased(MouseEvent me)
  4. public void mouseEntered(MouseEvent me)
  5. public void mouseExited(MouseEvent me)
  • MouseMotionListener
  1. public void mouseDragged(MouseEvent me)
  2. public void mouseMoved(MouseEvent me)
  • MouseWheelListener
  1. public void mouseWheelMoved(MouseEvent me)
  • ContainerListener
  1. public void componenetAdded(ContainerEvent  ce)
  2. public void componentRemoved(ContainerEvent ce)
  • ComponenetListener

  1. public void componentHidden(CompomentEvent ce)
  2. public void componentResized(CompomentEvent ce)
  3. public void componentShown(ComponentEvent ce)
  4. public void componentMoved(ComponentEvent ce)

  • AdjustmentListener
  1. public void adjustmentValueChanged(AdjustmentEvent ae)
  • KeyListener

  1. public void keyPressed(KeyEvent ke)
  2. public void keyReleased(KeyEvent ke)
  3. public void keyTyped(KeyEvent ke)

Adapter Class

                As you can see above, most of the listeners are having are having more than one abstract method, in such case if you implement an interface then you have to override all of it's abstract methods, which is a part of good programming practise. So, to resolve this problem adapter class has been introduced, which contains empty implementation of all those listener interface which has more than one abstract method. Adapter class implements following type listener interfaces
  • WindowAdapter- for WindowListener
  • MouseAdapter - for MouseMotionListener, MouseListener
  • KeyAdapter - for KeyListener
  • ComponentAdapter - for ComponentListener
  • ContainerAdapter - for ContainerListener
  • FocusAdapter - for FocusListener
  • MouseMotionAdapter - for MouseMotionListener

0 comments:

Post a Comment