Chapter 2: Swing Flashcards
In what sense is the Swing framework independent from the system?
The Swing Framework can look and behave identically on various operating systems like Windows, Macs or Linux.
How does a Swing component relate to the MVC model?
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 many models can be attached to a component?
Yes.
Ex.:
- JList -> ListModel, ListSelection
- JTable -> TableModel, TableColumnModel
- JTree -> TreeModel, TreeSelectionModel
Can different Swing components share the same model?
Yes.
Ex.:
- ButtonModel -> JButton, JtoggleButton, JCheckBox, JRadioButton, JMenu, JMenuItem, …
Do all components provide the same listeners?
Certain listeners are supported by all components (MouseListener, KeyListener) and some listeners are more specialized to specific components (ActionListener, ItemListener).
How many listeners can be attached to a component?
Multiple.
What is the purpose of ’SwingUtilities.invokeLater(…)’?
Special function to schedule code for execution in the GUI thread from a non-GUI thread.
What is a JFrame?
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.
Name a Swing component on which you can apply a layout.
JPanel is a JComponent on which you can apply a layout.
What is the relation between an Action and an ActionListener?
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.