Java : GUIs and Event Driven Programming - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Java : GUIs and Event Driven Programming

Description:

The event This is an event object that encapsulates information about the event. ... The primary reason to construct custom exception is because it allows the ... – PowerPoint PPT presentation

Number of Views:237
Avg rating:3.0/5.0
Slides: 10
Provided by: rockfor
Category:

less

Transcript and Presenter's Notes

Title: Java : GUIs and Event Driven Programming


1
Java GUIs and Event Driven Programming
  • Review notes, Module 10

2
10.1.1 Event driven programming
  • The Java language uses an event delegation model
    to handle events.
  • A source of an event This is an object that can
    generate an event object.
  • The event This is an event object that
    encapsulates information about the event.
  • The handler This is the object that can handle
    the event, which is performing some task.

3
10.1.1 Event driven programming
  • The code that the programmer will write to
    implement the event driven model consists of
    three steps.
  • These are creating a event source, such as a GUI
    component,
  • creating an instance of an object that implements
    the appropriate event listener interface,
  • and then connecting (registering) the listener
    object to the source object.

4
10.1.2 Event objects
5
10.1.4 Adapter classes
  • The adapter classes have the name of the Listener
    interface and the word Adapter. They are
    implemented as part of the java.awt.events
    package.

6
10.2.1 Inner classes
  • Anonymous classes are an alternative form of
    instance class creation.
  • An inner class is located in a .java file that
    matches the new class.

7
10.4.1 Applets and event-driven programming
  • The code in this method uses the getSource()
    method of the ActionEvent object to determine
    which object generated the event and the action
    to be performed.

8
Extra
  • The primary reason to construct custom exception
    is because it allows the programmer to tailor a
    handler to manage a specific exceptional problem
    that the enclosing method may encounter.
  • A key step in creating a custom checked exception
    handler is to subclass the custom class from
    class Exception .

9
Extra
  • The instructions that could be used in an
    actionPerformed method to differentiate between
    buttons buttonOne and buttonTwoif (
    e.getSource() btnOne )txtOne( "First button"
    )else if ( e.getSource() btnTwo )txtOne(
    "Second button" )
Write a Comment
User Comments (0)
About PowerShow.com