ECE 122 - PowerPoint PPT Presentation

About This Presentation
Title:

ECE 122

Description:

Many event listener interfaces, such as MouseListener, MouseMotionListener, ... Your event handler only OVERWRITE the methods you need. MouseAdapter ... – PowerPoint PPT presentation

Number of Views:13
Avg rating:3.0/5.0
Slides: 11
Provided by: wwwaliC
Category:
Tags: ece | listener | the

less

Transcript and Presenter's Notes

Title: ECE 122


1
ECE 122

2
JList
  • Demo JListDemo.java

3
Mouse Event Handling
  • MouseListener
  • MouseMotionListener
  • MouseInputListener. Extends interfaces of both
    MouseListener and MouseMotionListener to create a
    single interface

4
Methods of MouseListener
  • public void mousePressed(MouseEvent e)
  • public void mouseClicked(MouseEvent e)
  • public void mouseReleased(MouseEvent e)
  • public void mouseEntered(MouseEvent e)
  • public void mouseExited(MouseEvent e)

5
Methods of MouseMotionListener
  • public void mouseDragged(MouseEvent e)
  • public void mouseMoved(MouseEvent e)

6
Demo MouseDemo.java
7
Some event listener has many methods to implement
  • Many event listener interfaces, such as
    MouseListener, MouseMotionListener, contain
    multiple methods.
  • We only need to listen to one or two type of
    event(s).
  • We dont have to implement all declared methods.

8
Adapter classes
  • An adapter class provides a default
    implementation of every methods of a
    corresponding listener interface.
  • Such default implementation is with empty method
    body.
  • Your event handler extends an adapter.
  • Your event handler only OVERWRITE the methods you
    need.

9
MouseAdapter
  • MouseAdapter implements MouseListener
  • Demo MouseAdapterDemo.java

10
More Adapter classes
Event adapter Listener interface
ComponentAdapter ComponentListener
ContainerAdapter ContainerListener
FocusAdapter FocusListener
KeyAdapter KeyListener
MouseAdapter MouseListener
MouseMotionAdapter MouseMotionListener
WindowAdapter WindowListener
Write a Comment
User Comments (0)
About PowerShow.com