Events and Listeners Flashcards

1
Q

What method should a class that is the source of methods contain

A

A method that allows for registration of listeners - one of reach listener event type

By convention the methods look like:
public void addEventCategoryListener (EventCategoryListener this)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an event

What is contained in event classes

A

A state change

Event classes contain methods that can be used to implement the interface

Each event has corresponding listener interface

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain the relationship between event listener interfaces, event notification methods and event classes

A

Event listeners (e.g. KeyListener) consist of multiple event notification methods (e.g. keyPressed, keyReleased). This is because when an event listener is notified, it deals with the event via these methods.

Event notification methods categorized into event classes (e.g. KeyEvent)

Event classes are directly linked to an event listener interface

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe the java event framework (structure)

A

One abstract class => EventObject

An interface => EventListener

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Explain the structure of the delegation model

A

SOURCE
Event generated at this level, source must register listeners.
Event generation occurs when there is some change to the internal state of the source

LISTENER
An object that is notified that an event has occurred
Registered with the source of an event
Methods of listener object deals with event when notified

EVENT
An object that contains information about a state change in a source

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When should you use events and listeners in your program

A

Any situation where you’re waiting for something in you program to happen but you can’t make it happen

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why should we use event-driven programming when implementing GUI’s

A

GUI’s have multiple components that can be interacted with
Programs need to react to all these different events
When implementing IDEs, we need to implement functionality and understand events

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is event-driven programming
Give one advantage
Give one disadvantage

A

Resources are released when notified that an event has occurred

Better use of resources

More complex to implement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a polling event
Give one advantage
Give one disadvantage

A

When you keep checking for the events’ occurrence, best way to implement this is by using a while loop

Easy to implement

Wasteful of resources

How well did you know this?
1
Not at all
2
3
4
5
Perfectly