Unit 4 Flashcards
What is the primary focus of event-driven programming?
Program flow/execution driven by events
Events include user interactions, sensor signals, and messages from other threads.
What are the three components of the Model-View-Controller (MVC) design pattern?
- Model: stores the state of your program
- View: displays the state of your program to the user
- Controller: changes the state of your program
What does the Model component in MVC represent?
The state of the world and data describing the state of your program
Includes user authorization and program execution state.
What is the role of the View component in MVC?
Represents the current state of the model and communicates program data to the user
Can be a Command Line Interface (CLI), Graphical User Interface (GUI), or hardware.
What does the Controller component do in MVC?
Changes the model by adding, editing, or removing data
Typically part of an event callback.
What is a limitation of imperative programming?
Inflexible sequence and cannot act ‘out of order’
User must respond in the right way and there is no concurrency.
What is a callback function in event-driven programming?
A function that runs when a specific event occurs
True or False: Event-driven programming allows for multiple types of user inputs such as mouse clicks and keystrokes.
True
Fill in the blank: In event-driven programming, applications recognize inputs and take the appropriate _______.
[action]
What is a dispatcher in an event-driven system?
Listens for events, determines when an event occurs, and looks up the event handler/callback
What happens when an event is detected in an event-driven program?
A callback function is executed
What are the two approaches to updating the View in MVC?
- Push approach: Model change event -> view update
- Pull approach: View refresh event -> view update
What is the Observer pattern in event-driven programming?
A one-to-many model where one subject notifies multiple observers
What is one catch of event-driven programming?
Event-driven code executes indirectly, leading to complex callback chains
What is the Java Observer pattern?
A simplified abstraction providing Observable class and Observer interface
What does the Observable class in Java do?
Manages notification behaviors and allows observers to subscribe
What is the purpose of the Observer interface in Java?
Defines how to respond when an observable notifies
What is a key benefit of thinking about problems as event-driven?
Events encapsulate all necessary information as a message
What is a common application of event-driven programming?
Graphical User Interfaces (GUI)
What is an example of an external event that can trigger a model change in MVC?
An external signal event like an image download completion
What are the three main Java GUI libraries?
AWT, Swing, JavaFX
AWT stands for Abstract Window Toolkit, Swing is an extension of AWT, and JavaFX is a modern GUI toolkit introduced later.
What is the primary purpose of the Java Swing GUI Library?
To provide a toolkit for creating graphical user interfaces in Java applications.
In which year was the Java Swing toolkit introduced?
1997
What are the two levels of API provided by the original Java GUI toolkit?
- General Java <-> OS interface for windowing and layout management
- GUI event subsystem