GUI1 Flashcards
What is the purpose of the JLabel constructor with string, Icon, and alignment arguments?
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);
What is the function of the setToolTipText method in JLabel?
It sets a tooltip that appears when the mouse hovers over the JLabel.
Example: label2.setToolTipText(“This is label2”);
What does the validate method do in a container?
It triggers the layout for the container and all child containers, marking the container as valid.
What is the default state of a newly created component?
Invalid.
What is GridLayout?
A layout manager that places components in a grid of cells, with each component taking all available space within its cell.
What happens to the cell size in a GridLayout when the window is resized?
The cell size changes so that all cells are as large as possible given the available space.
What are some common layout managers in Java?
- FlowLayout
- BorderLayout
- BoxLayout
- CardLayout
- GridLayout
- GridBagLayout
- GroupLayout
- SpringLayout
What distinguishes Swing from AWT?
Swing components are implemented in Java, offering more portability and flexibility than AWT components, which depend on the underlying platform.
What are lightweight components in Java?
Components not tied directly to the GUI components supported by the underlying platform.
What are heavyweight components?
Components that are tied directly to the local platform, such as AWT components.
What is the superclass of all lightweight Swing components?
JComponent.
What is a functional interface in Java?
An interface containing only one abstract method, used extensively with Java SE 8’s lambda capabilities.
Which interfaces are commonly used as functional interfaces in Java SE?
- ActionListener
- Comparator
- Runnable
What is an anonymous inner class?
A special form of inner class declared without a name, typically used for event handling.
What is the role of listenerList in a JComponent?
It maintains references to the registered listeners for that component.
What must an object be to handle an action event?
It must be an instance of the EventHandler<T> interface.</T>
True or False: The event information is stored in an object of a class that extends AWTEvent.
True.