Chapter 2: Swing Flashcards

1
Q

In what sense is the Swing framework independent from the system?

A

The Swing Framework can look and behave identically on various operating systems like Windows, Macs or Linux.

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

How does a Swing component relate to the MVC model?

A

Based on MVC model, but:
- View and Controller part are collapsed into UI
- Model remains Model
-> When new Swing component is created a corresponding model is automatically created

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

How many models can be attached to a component?

A

Yes.
Ex.:
- JList -> ListModel, ListSelection
- JTable -> TableModel, TableColumnModel
- JTree -> TreeModel, TreeSelectionModel

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

Can different Swing components share the same model?

A

Yes.
Ex.:
- ButtonModel -> JButton, JtoggleButton, JCheckBox, JRadioButton, JMenu, JMenuItem, …

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

Do all components provide the same listeners?

A

Certain listeners are supported by all components (MouseListener, KeyListener) and some listeners are more specialized to specific components (ActionListener, ItemListener).

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

How many listeners can be attached to a component?

A

Multiple.

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

What is the purpose of ’SwingUtilities.invokeLater(…)’?

A

Special function to schedule code for execution in the GUI thread from a non-GUI thread.

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

What is a JFrame?

A

Swing component which is placed at the top-level container and allows us to create a window when the JFrame object is invoked, well configured and when the code is executed.

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

Name a Swing component on which you can apply a layout.

A

JPanel is a JComponent on which you can apply a layout.

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

What is the relation between an Action and an ActionListener?

A

The relationship between an Action and an ActionListener is based on the observer design pattern, where the ActionListener acts as the observer that “listens” to and reacts to events triggered by the Action.

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