Podcast
Questions and Answers
AWT components are tied to the local platform and are called ______ components.
AWT components are tied to the local platform and are called ______ components.
heavyweight
Class ______ declares many of the attributes and behaviors common to the GUI components in packages java.awt and javax.swing.
Class ______ declares many of the attributes and behaviors common to the GUI components in packages java.awt and javax.swing.
Component
Class ______ is a subclass of Component.
Class ______ is a subclass of Component.
Container
Any object that is a ______ can be used to organize other Components in a GUI.
Any object that is a ______ can be used to organize other Components in a GUI.
Signup and view all the answers
Class ______ is the superclass of all lightweight Swing components, all of which are also Containers.
Class ______ is the superclass of all lightweight Swing components, all of which are also Containers.
Signup and view all the answers
Several Swing components are ______ components.
Several Swing components are ______ components.
Signup and view all the answers
Java allows you to declare classes inside other classes — these are called ______ classes.
Java allows you to declare classes inside other classes — these are called ______ classes.
Signup and view all the answers
Before an object of an ______ class can be created, there must first be an object of the top-level class that contains the inner class.
Before an object of an ______ class can be created, there must first be an object of the top-level class that contains the inner class.
Signup and view all the answers
There is also a special relationship between these objects — the ______ object is allowed to directly access all the variables and methods of the outer class.
There is also a special relationship between these objects — the ______ object is allowed to directly access all the variables and methods of the outer class.
Signup and view all the answers
A ______ class that is static does not require an object of its top-level class and does not implicitly have a reference to an object of the top-level class.
A ______ class that is static does not require an object of its top-level class and does not implicitly have a reference to an object of the top-level class.
Signup and view all the answers
Event handlers tend to be specific to the application in which they are defined, so they are often implemented as private ______ classes.
Event handlers tend to be specific to the application in which they are defined, so they are often implemented as private ______ classes.
Signup and view all the answers
GUI components can generate many ______ in response to user interactions.
GUI components can generate many ______ in response to user interactions.
Signup and view all the answers
BorderLayout arranges components into five regions: NORTH, SOUTH, EAST, WEST and ______ .
BorderLayout arranges components into five regions: NORTH, SOUTH, EAST, WEST and ______ .
Signup and view all the answers
Methods addMouseListener and addMouseMotionListener register ______ and MouseMotionListeners, respectively.
Methods addMouseListener and addMouseMotionListener register ______ and MouseMotionListeners, respectively.
Signup and view all the answers
MouseEvent methods getX and getY return the x- and ycoordinates of the mouse at the time the ______ occurred.
MouseEvent methods getX and getY return the x- and ycoordinates of the mouse at the time the ______ occurred.
Signup and view all the answers
An adapter class implements an interface and provides a default implementation (with an empty method body) of each method in the ______.
An adapter class implements an interface and provides a default implementation (with an empty method body) of each method in the ______.
Signup and view all the answers
You extend an adapter class to inherit the default implementation of every method and override only the method(s) you need for ______ handling.
You extend an adapter class to inherit the default implementation of every method and override only the method(s) you need for ______ handling.
Signup and view all the answers
Many event-listener interfaces contain multiple ______.
Many event-listener interfaces contain multiple ______.
Signup and view all the answers
Package javax.swing.event contains interface ______ which extends interfaces MouseListener and MouseMotionListener
Package javax.swing.event contains interface ______ which extends interfaces MouseListener and MouseMotionListener
Signup and view all the answers
MouseListener and MouseMotionListener methods are called when the ______ interacts with a Component
MouseListener and MouseMotionListener methods are called when the ______ interacts with a Component
Signup and view all the answers
Each mouse event-handling method receives a ______ object that contains information about the mouse event
Each mouse event-handling method receives a ______ object that contains information about the mouse event
Signup and view all the answers
Coordinates are measured from the upper-left corner of the GUI component on which the event ______
Coordinates are measured from the upper-left corner of the GUI component on which the event ______
Signup and view all the answers
Interface ______ enables applications to respond to the rotation of a mouse wheel
Interface ______ enables applications to respond to the rotation of a mouse wheel
Signup and view all the answers
Class ______ contains methods that enable the event handler to obtain information about the amount of wheel rotation
Class ______ contains methods that enable the event handler to obtain information about the amount of wheel rotation
Signup and view all the answers
The application chooses the number to be guessed by selecting an integer at random in the range 1–______.
The application chooses the number to be guessed by selecting an integer at random in the range 1–______.
Signup and view all the answers
The background color should change to either ______ or blue.
The background color should change to either ______ or blue.
Signup and view all the answers
A JLabel should display either "Too High" or "Too ______" to help the user zero in.
A JLabel should display either "Too High" or "Too ______" to help the user zero in.
Signup and view all the answers
When the user gets the correct answer, "______!" should be displayed.
When the user gets the correct answer, "______!" should be displayed.
Signup and view all the answers
A JButton should be provided to allow the user to play the game ______.
A JButton should be provided to allow the user to play the game ______.
Signup and view all the answers
When the JButton is clicked, a new random number should be generated and the input JTextField changed to be ______.
When the JButton is clicked, a new random number should be generated and the input JTextField changed to be ______.
Signup and view all the answers
Study Notes
GUI Components and Events
- Package
javax.swing.event
contains interfaceMouseInputListener
, which extends interfacesMouseListener
andMouseMotionListener
. -
MouseListener
andMouseMotionListener
methods are called when the mouse interacts with a component if appropriate event-listener objects are registered for that component.
Mouse Events
- Each mouse event-handling method receives a
MouseEvent
object that contains information about the mouse event that occurred. -
MouseEvent
object contains the x- and y-coordinates of the location where the event occurred. - Coordinates are measured from the upper-left corner of the GUI component on which the event occurred.
Mouse Wheel Events
- Interface
MouseWheelListener
enables applications to respond to the rotation of a mouse wheel. - Method
mouseWheelMoved
receives aMouseWheelEvent
as its argument. - Class
MouseWheelEvent
contains methods that enable the event handler to obtain information about the amount of wheel rotation.
Nested Classes
- Java allows declaring classes inside other classes, known as nested classes.
- Nested classes can be static or non-static.
- Non-static nested classes are called inner classes and are frequently used to implement event handlers.
Inner Classes
- Before an object of an inner class can be created, there must first be an object of the top-level class that contains the inner class.
- Inner-class object implicitly has a reference to an object of its top-level class.
- A nested class that is static does not require an object of its top-level class and does not implicitly have a reference to an object of the top-level class.
- Inner classes can be declared public, protected, or private.
GUI Components
- GUI components can generate many events in response to user interactions.
- Some AWT components are heavyweight components, while Swing components are lightweight components.
- Class
Component
declares many of the attributes and behaviors common to GUI components. - Class
Container
is a subclass ofComponent
and is used to organize and display components on the screen. - Class
JComponent
is a subclass ofContainer
and is the superclass of all lightweight Swing components.
Layout Managers
-
BorderLayout
arranges components into five regions: NORTH, SOUTH, EAST, WEST, and CENTER. -
BorderLayout
sizes the component in the CENTER to use all available space that is not occupied.
Event Listeners
- Methods
addMouseListener
andaddMouseMotionListener
registerMouseListeners
andMouseMotionListeners
, respectively. - Adapter classes implement an interface and provide a default implementation of each method in the interface.
- You extend an adapter class to inherit the default implementation of every method and override only the method(s) you need for event handling.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Learn about the differences between AWT and Swing components in Java, including heavyweight and lightweight components. Understand the role of the Class Component in Java GUI development.