Swing & awt 2 Flashcards

(64 cards)

1
Q

What does EmptyBorder class do in Java Swing?

A

It provides transparent, empty space around a component to improve visual separation and readability.

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

The ___ class (found in ___) is a concrete implementation of the Border interface that provides __, __ around a component.

A
  • EmptyBorder
  • javax.swing.border
  • transparent
  • empty space
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Its primary use is to add __ or __, improving the __ ___ and ___ of UI elements.

A
  • padding or margins
  • visual separation and readability
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the problems with a monolithic approach to GUI development in Java?

A

It causes poor readability, reduced maintainability, and increases the risk of bugs in unrelated parts of the GUI.

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

___ arises when a single class has thousands of lines of code for various GUI elements, making it hard to identify specific actions or layouts, leading to __ and ___ tasks.

A

Lack of readability
- tedious
- error-prone

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

___: ___ or ___ in a large codebase increase the risk of introducing __ in unrelated GUI parts.

A
  • Reduced Maintainability
  • Bugs or new features
  • defects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The solution lies in applying ___ principles, particularly ___, by defining separate classes for distinct GUI elements or functional parts of your interface.

A
  • Object-Oriented Programming (OOP)
  • encapsulation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the benefit of creating GUIs as separate classes?

A

It improves modularity, readability, maintainability, collaboration, and testability.

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

___ refers to the __ to which a system’s components can be __ and __. When you create GUIs as classes, you achieve __ modularity.

A
  • Modularity
  • degree
  • separated and combined
  • high modularity
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the benefits of achieving high modularity?

A
  1. Improved Readability and Organization
  2. Enhanced Maintainability and Debugging
  3. Facilitates Team Collaboration
  4. Testability
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

___ : Each class has a ___, making the codebase easier to __ and __. Developers can quickly locate the relevant code for a specific __ element or feature.

A
  • Improved Readability and Organization
  • single responsibility
  • navigate and understand
  • specific UI
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

___ : Changes or bug fixes can be __ to a specific __ (class) without affecting unrelated parts of the GUI. This reduces the risk of introducing new __ and simplifies the __ process.

A
  • Enhanced Maintainability and Debugging
  • isolated
  • specific module
  • errors
  • debugging
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

__ : In larger projects, different team members can work on separate __ classes concurrently, leading to more __ cycles and __ conflicts.

A
  • Facilitates Team Collaboration
  • GUI
  • efficient development
  • fewer merge
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

__: Individual __ components or __ can be more easily tested in __, promoting the creation of __ and reliable __.

A
  • Testability
  • GUI
  • panels
  • isolation
  • creation of robust
  • reliable UIs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

It is used for password input. Characters typed are not shown.

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

What does the JPasswordField do?

A

It allows secure text input where characters appear as asterisks(*) or another character.

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

How do you import JPasswordField?

A

import javax.swing.JPasswordField;

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

What is the syntax for creating a JPasswordField with a specified width?

A

JPasswordField passwordField = new JPasswordField(int columns);

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

How wide the field is in number of characters (optional).

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

It is used when you want the user to enter multiple lines of text, like comments or descriptions.

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

What component is used for multi-line text input?

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

How do you import JTextArea?

A
  • import javax.swing.JTextArea;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How do you declare a JTextArea?

A

JTextArea textArea = new JTextArea(int rows, int columns);

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

It lets users select multiple options from a list.

A
  • JCheckBox
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
How do you import JCheckBox?
- import javax.swing.JCheckBox;
26
How do you declare JCheckBox?
JCheckBox checkBox = new JCheckBox(String label);
27
The visible text beside the checkbox
- label
28
This allows user to select only one form a group of options.
JRadioButton + ButtonGroup
29
Use __ to group them together.
- ButtonGroup
30
How do import JRadioButton and ButtonGroup?
- importjavax.swing.JRadioButton; - importjavax.swing.ButtonGroup;
31
How do you declare JRadioButton and ButtonGroup?
JRadioButton: JRadioButton r1 = new JRadioButton("Male"); JRadioButton r2 = new JRadioButton("Female"); ButtonGroup: ButtonGroup genderGroup = new ButtonGroup(); genderGroup.add(r1); genderGroup.add(r2);
32
It creates a drop-down list where the user selects one item.
- JComboBox
33
JComboBox
It is a drop-down menu
34
How do you import JComboBox?
import javax.swing.JComboBox;
35
How do you declare JComboBox?
JComboBox combo = new JComboBox<>(new String[] {"Option1", "Option2"});
36
Pass an __ (or __) representing the choices.
- array of strings - or objects
37
It is a Tabular Data Display
JTable
38
Display data in a __ with __ and __ (like __ or __)
- grid format - rows and columns - like Excel or a database table
39
How do you import JTable?
import javax.swing.Jtable;
40
How do you declare JTable?
JTable table = new JTable(Object[][] data, Object[] columnNames);
41
It makes the components scrollable.
- JScrollPane
42
Wraps around other components like JTextArea or JTable to add scrollbars when content is too large.
JScrollPane
43
How do you import JScrollPane?
import javex.swing.JScrollPane;
44
How do you declare JScrollPane?
JScrollPane scrollPane = new JScrollPane(Component component); The component that needs scrolling (e.g., JTextArea, JTable)
45
An __ is anything that the user does while interacting with a ___ (GUI). It is a __ that something happened —like ___, __, or __.
- Event - Graphical User Interface - signal - clicking, typing, or selecting
46
__ uses a structured way to handle events, called the __ __ __. This model separates the __ from the ___.
- Java - Event Delegation Model - event source - event handling logic
47
__ is the process of __, __, and __ to user interactions in a Java GUI application.
- Event handling - detecting, listening to, responding
48
These __ -- like clicking a button, typing a text field, or selecting from a dropdown -- are called __.
- interactions - events
49
__ is the mechanism that allows your program to react to those events.
- EVent handling
50
What is Event handling?
It is the process of detecting, listening to, and responding to user interactions in a Java GUI application.
51
What are the components of the Event Handling Model?
1. Event Source 2. Event Object 3. Event Listener 4. Event Handler
52
__ is the component that the user interacts with. Think of it as the __.
- Event Source - trigger
53
Examples of Event Source and what generate events when the user interacts with them?
- JButton (ActionEvent) - JTextField (ActionEvent or KeyEvent) - JCheckBox (ItemEvent) - JRadioButtion (ActionEvent) - JComboBox (ActionEvent or ItemEvent) - JTextArea (KeyEvent for typing)
54
What is the responsibility of Event Source?
- it generates the event when an action occurs
55
__ is an object that contains all the information about the event. Think of it as the __ carrying event details.
- Event Object - messenger
56
Examples of Event Object.
- ActionEvent - ItemEvent - KeyEvent
57
What is the responsibility of Event Object?
Carries the details like: - What component was involved (getSource()) - What action was taken (getActionCommand())
58
It is an interface in Java that must be implemented to handle a specific type of event. Think of it as a __ waiting for something to happen.
- Event Listener - watcher
59
Examples of Event Listener.
- ActionListener, ItemListener, KeyListener
60
Responsibility of an EVent Listener: __ for an event and __ when it happens.
- Listenes - responds
61
The method inside the listener that is automatically called when the ecent occurs. Think of it as the __ -- the one who takes action.
- Event Handler - responder
62
Example Method
actionPerformed(ActionEvent e)
63
Responsibility of Event Handler:
Executes the code you want to run (like displaying a message, saving data, etc.)
64
Real-Life Analogy: Imagine you are in a classroom. The __ is like a student raising their hand (event source). The __ is the hand being raised. The __ is the teacher watching the class. The __ is the teacher responding, like calling on the student.
- button - event - listener - handler