GUI1 Flashcards

1
Q

What is the purpose of the JLabel constructor with string, Icon, and alignment arguments?

A

To create a JLabel that displays both text and an icon with specified alignment.

Example: JLabel label2 = new JLabel(“Label with text and icon”, bug, SwingConstants.LEFT);

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

What is the function of the setToolTipText method in JLabel?

A

It sets a tooltip that appears when the mouse hovers over the JLabel.

Example: label2.setToolTipText(“This is label2”);

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

What does the validate method do in a container?

A

It triggers the layout for the container and all child containers, marking the container as valid.

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

What is the default state of a newly created component?

A

Invalid.

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

What is GridLayout?

A

A layout manager that places components in a grid of cells, with each component taking all available space within its cell.

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

What happens to the cell size in a GridLayout when the window is resized?

A

The cell size changes so that all cells are as large as possible given the available space.

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

What are some common layout managers in Java?

A
  • FlowLayout
  • BorderLayout
  • BoxLayout
  • CardLayout
  • GridLayout
  • GridBagLayout
  • GroupLayout
  • SpringLayout
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What distinguishes Swing from AWT?

A

Swing components are implemented in Java, offering more portability and flexibility than AWT components, which depend on the underlying platform.

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

What are lightweight components in Java?

A

Components not tied directly to the GUI components supported by the underlying platform.

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

What are heavyweight components?

A

Components that are tied directly to the local platform, such as AWT components.

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

What is the superclass of all lightweight Swing components?

A

JComponent.

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

What is a functional interface in Java?

A

An interface containing only one abstract method, used extensively with Java SE 8’s lambda capabilities.

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

Which interfaces are commonly used as functional interfaces in Java SE?

A
  • ActionListener
  • Comparator
  • Runnable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is an anonymous inner class?

A

A special form of inner class declared without a name, typically used for event handling.

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

What is the role of listenerList in a JComponent?

A

It maintains references to the registered listeners for that component.

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

What must an object be to handle an action event?

A

It must be an instance of the EventHandler<T> interface.</T>

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

True or False: The event information is stored in an object of a class that extends AWTEvent.

A

True.

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

What occurs when an event happens in a GUI component?

A

The event is dispatched to the event listeners of the appropriate type.

19
Q

What is the significance of the pack method in a window?

A

It validates the window and lays out the window’s component hierarchy for the first time.

20
Q

What are the two requirements for a handler of an action event?

A
  1. The object must be an instance of the EventHandler<T> interface. 2. The handler must be registered with the event source object using source.setOnAction(handler).</T>
21
Q

What does <T> signify in EventHandler?</T>

A

T is a generic type that is a subtype of Event.

22
Q

What method must be overridden in a handler class to respond to an action event?

A

handle(ActionEvent)

23
Q

What is an event listener in the context of GUI events?

A

An object of a class that implements one or more of the event-listener interfaces from packages java.awt.event and javax.swing.event.

24
Q

True or False: An event is an object created from an event source.

25
What are the corresponding event-listener interfaces for ActionEvents, MouseEvents, and KeyEvents?
* ActionEvents: ActionListeners * MouseEvents: MouseListeners and MouseMotionListeners * KeyEvents: KeyListeners
26
What does a GUI component receive when an event occurs?
A unique event ID specifying the event type.
27
What is the purpose of the event ID in a GUI component?
To decide the listener type to which the event should be dispatched and which method to call on each listener object.
28
List the steps to build a GUI from bottom up.
* Create Frame * Create Panel * Create Components * Create Listeners * Add listeners into components * Add components into panel * Add panel into frame
29
What is the function of JOptionPane in Java?
To provide static constants for message dialogs and to interact with the user through input and message dialogs.
30
What type of dialog does ERROR_MESSAGE represent in JOptionPane?
A dialog that indicates an error to the user.
31
Fill in the blank: A _______ dialog poses a question to the user and normally requires a response.
QUESTION_MESSAGE
32
What must a program do after receiving user input from JOptionPane?
Convert the String to an int.
33
What is the class name of the example program that uses JOptionPane for input and output?
Addition
34
What is a graphical user interface (GUI)?
A user-friendly mechanism for interacting with an application, often containing components like title bars, menu bars, buttons, and combo boxes.
35
What is the main package for Swing GUI components?
javax.swing
36
What does the GUI Builder's Source button do?
Enables you to view a class's source code.
37
What is the role of the Properties Window in the GUI Builder?
Displays the properties of the component currently selected.
38
What does Automatic Component Positioning (Snapping) assist with?
Positioning components based on the operating system's look and feel.
39
True or False: Visual feedback helps in identifying component positioning relationships.
True
40
What is Free Design in the GUI Builder?
Allows you to build forms by placing components where you want without concern for layout attributes.
41
What type of component is a JButton?
Triggers an event when clicked with the mouse.
42
Name a basic GUI component that enables user input.
JTextField
43
What does JPanel provide in a GUI?
An area in which components can be placed and organized.
44
What type of message does INFORMATION_MESSAGE represent?
A dialog with an informational message to the user.