Unit 4 Flashcards

(18 cards)

1
Q

What is imperative programming?

A

Program flow is specified by the programmer

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

Why might imperative programming be the best solution to all problems?

A

Inflexible sequence: cannot act “out of order”, user must respond in the right way
No concurrency: can’t act “out of turn”, must wait for user to input/respond
Users with multiple possible inputs (mouse, keystrokes, button presses, etc.)
Multiple users
Things happening without user input: file downloads complete, time elapses

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

What is event driven programming?

A

Program flow/execution is driven by events
Program executes by detecting and identifying an event, then running a callback function which determines what to do when the event occurs

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

Why might event-driven programming not be ideal in all cases?

A

The code executes indirectly
- The chain of cause/effect can grow deep
- Code does not execute sequentially
- Requires a strong mental model and naming scheme
Increased overhead for execution
- Events are messages which must be created and passed
- Flexibility in exchange for speed of execution

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

What is the “observer” pattern?

A

A one-to-many event driven model
- One subject (event generator)
- One or more observers (handlers)
Observers subscribe to a subject by registering
Subject notifies all subscribed observers

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

What is MVC?

A

Model-View-Controller
Model: store the state of your program (data)
View: display the state of your program to the user (output)
Controller: change the state of your program (input)

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

Describe the Model component in MVC

A
  • Model is the state of the world
    – Data describing the world of your program
  • Specific to the situation or entities you are modelling
    – Data describing the state of your program
  • Is the user authorized? Have they asked to quit?
  • Model is built out of
    – Data structures (COSC 2010)
    – Program execution state
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Describe the View component in MVC

A
  • View is what the user sees
    – Represents the current state of the model (or part of it)
    – Communicates program and data tu user
    – Could be CLI, GUI, hardware, etc.
  • If the model changes, the view becomes out-of-date (stale)
    – A push approach
  • Model change event -> view update (to capture new model)
    – A pull approach
  • View refresh event -> view update to capture new model
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Describe the Controller component in MVC

A
  • Controller is what changes the model
    – Controller code adds/edits/removes data from the model
    – Alters or updates program state
  • Typically part of an event callback
    – User input event -> callback that modifies the model
    – External signal event -> modify the model
  • Image download complete -> replace “placeholder” image with real one
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the pros and cons of Swing?

A

Pros: appearance can be customized and/or standardized across OS
Cons: can be slower (if we’re careless), “near-match” native appearance

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

True or False: Swing extends AWT?

A

True
AWT handles OS interactions
Swing provides customization

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

Describe Swing containers

A

Containers hold/organize components (including other containers)
Top level containers can “stand alone”
- JFrame: window with title border
- JWindow: window without title or border
- JDialog: popup, usually to get input
- JPanel: simplest container, cannot be top-level container

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

What is a content pane?

A

Swing containers all have a content pane
It holds the components within the pane
Manages how they are arranged and drawn

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

What is a layout manager?

A

It arranges components within a container (content pane)
Layout manager tracks what’s been added, what takes up space, what is visible

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

What are the five “regions” in a container?

A

North
South
East
West
Center
Note: regions are greedy; if not occupied, other regions grow to fill

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

What does “enabling” a JButton mean?

A

Instantiate a JButton (add to layout)
Instantiate an ActionListener
JButton.addActionListener(ActionListener)

17
Q

True or False: paint() is invoked automatically whenever the component needs to be redrawn

18
Q

What three steps does Swing break the paint process into?

A

paintComponent : paint yourself
paintBorder : paint your edges
paintChildren : paint your contained components