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.

A

True

25
Q

What are the corresponding event-listener interfaces for ActionEvents, MouseEvents, and KeyEvents?

A
  • ActionEvents: ActionListeners
  • MouseEvents: MouseListeners and MouseMotionListeners
  • KeyEvents: KeyListeners
26
Q

What does a GUI component receive when an event occurs?

A

A unique event ID specifying the event type.

27
Q

What is the purpose of the event ID in a GUI component?

A

To decide the listener type to which the event should be dispatched and which method to call on each listener object.

28
Q

List the steps to build a GUI from bottom up.

A
  • Create Frame
  • Create Panel
  • Create Components
  • Create Listeners
  • Add listeners into components
  • Add components into panel
  • Add panel into frame
29
Q

What is the function of JOptionPane in Java?

A

To provide static constants for message dialogs and to interact with the user through input and message dialogs.

30
Q

What type of dialog does ERROR_MESSAGE represent in JOptionPane?

A

A dialog that indicates an error to the user.

31
Q

Fill in the blank: A _______ dialog poses a question to the user and normally requires a response.

A

QUESTION_MESSAGE

32
Q

What must a program do after receiving user input from JOptionPane?

A

Convert the String to an int.

33
Q

What is the class name of the example program that uses JOptionPane for input and output?

A

Addition

34
Q

What is a graphical user interface (GUI)?

A

A user-friendly mechanism for interacting with an application, often containing components like title bars, menu bars, buttons, and combo boxes.

35
Q

What is the main package for Swing GUI components?

A

javax.swing

36
Q

What does the GUI Builder’s Source button do?

A

Enables you to view a class’s source code.

37
Q

What is the role of the Properties Window in the GUI Builder?

A

Displays the properties of the component currently selected.

38
Q

What does Automatic Component Positioning (Snapping) assist with?

A

Positioning components based on the operating system’s look and feel.

39
Q

True or False: Visual feedback helps in identifying component positioning relationships.

A

True

40
Q

What is Free Design in the GUI Builder?

A

Allows you to build forms by placing components where you want without concern for layout attributes.

41
Q

What type of component is a JButton?

A

Triggers an event when clicked with the mouse.

42
Q

Name a basic GUI component that enables user input.

A

JTextField

43
Q

What does JPanel provide in a GUI?

A

An area in which components can be placed and organized.

44
Q

What type of message does INFORMATION_MESSAGE represent?

A

A dialog with an informational message to the user.