Unit 4 Flashcards

1
Q

What is the primary focus of event-driven programming?

A

Program flow/execution driven by events

Events include user interactions, sensor signals, and messages from other threads.

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

What are the three components of the Model-View-Controller (MVC) design pattern?

A
  • Model: stores the state of your program
  • View: displays the state of your program to the user
  • Controller: changes the state of your program
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the Model component in MVC represent?

A

The state of the world and data describing the state of your program

Includes user authorization and program execution state.

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

What is the role of the View component in MVC?

A

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.

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

What does the Controller component do in MVC?

A

Changes the model by adding, editing, or removing data

Typically part of an event callback.

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

What is a limitation of imperative programming?

A

Inflexible sequence and cannot act ‘out of order’

User must respond in the right way and there is no concurrency.

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

What is a callback function in event-driven programming?

A

A function that runs when a specific event occurs

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

True or False: Event-driven programming allows for multiple types of user inputs such as mouse clicks and keystrokes.

A

True

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

Fill in the blank: In event-driven programming, applications recognize inputs and take the appropriate _______.

A

[action]

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

What is a dispatcher in an event-driven system?

A

Listens for events, determines when an event occurs, and looks up the event handler/callback

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

What happens when an event is detected in an event-driven program?

A

A callback function is executed

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

What are the two approaches to updating the View in MVC?

A
  • Push approach: Model change event -> view update
  • Pull approach: View refresh event -> view update
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the Observer pattern in event-driven programming?

A

A one-to-many model where one subject notifies multiple observers

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

What is one catch of event-driven programming?

A

Event-driven code executes indirectly, leading to complex callback chains

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

What is the Java Observer pattern?

A

A simplified abstraction providing Observable class and Observer interface

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

What does the Observable class in Java do?

A

Manages notification behaviors and allows observers to subscribe

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

What is the purpose of the Observer interface in Java?

A

Defines how to respond when an observable notifies

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

What is a key benefit of thinking about problems as event-driven?

A

Events encapsulate all necessary information as a message

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

What is a common application of event-driven programming?

A

Graphical User Interfaces (GUI)

20
Q

What is an example of an external event that can trigger a model change in MVC?

A

An external signal event like an image download completion

21
Q

What are the three main Java GUI libraries?

A

AWT, Swing, JavaFX

AWT stands for Abstract Window Toolkit, Swing is an extension of AWT, and JavaFX is a modern GUI toolkit introduced later.

22
Q

What is the primary purpose of the Java Swing GUI Library?

A

To provide a toolkit for creating graphical user interfaces in Java applications.

23
Q

In which year was the Java Swing toolkit introduced?

24
Q

What are the two levels of API provided by the original Java GUI toolkit?

A
  • General Java <-> OS interface for windowing and layout management
  • GUI event subsystem
25
What is a key advantage of AWT?
Fast and native appearance on all platforms.
26
What is a significant disadvantage of AWT?
Limited customization and consistency.
27
How does Swing differ from AWT in terms of appearance?
Swing allows for greater customization and standardized appearance across operating systems.
28
What does the term 'lightweight approach' refer to in Swing?
Swing components are drawn/styled within Java, rather than relying on OS draws.
29
What is the role of layout managers in Swing?
To arrange components within a container according to its type/configuration.
30
Name the default layout for top-level containers in Swing.
BorderLayout
31
What are the five regions defined by BorderLayout?
* NORTH * SOUTH * EAST * WEST * CENTER
32
What is the default layout for JPanel?
FlowLayout
33
What layout allows components to span multiple rows or columns?
GridBagLayout
34
List some common Swing components.
* JButton * JTextField * JCheckBox * JRadioButton * JTextArea
35
What event do JButtons generate when interacted with?
ActionEvent
36
What interface must be implemented to respond to ActionEvents?
ActionListener
37
What method is called when an ActionEvent occurs?
actionPerformed(ActionEvent e)
38
What are the three steps in Swing's painting process?
* paintComponent * paintBorder * paintChildren
39
What method must be overridden to create a custom component in Swing?
paintComponent
40
What is the purpose of the repaint() method in Swing?
To call paint() and update the component's visual representation.
41
What is a common pattern for creating animations in Swing?
* Create a custom component * Override paintComponent * Set up a Timer to generate ActionEvents * Repaint the view
42
What does the term 'MVC' stand for in the context of Swing components?
Model-View-Controller
43
What kind of events does a MouseListener respond to?
Mouse actions like clicks, drags, and movements.
44
True or False: Swing components can only be added to a top-level container.
False
45
Fill in the blank: A __________ is a window without a title or border.
JWindow