Java GUI Components: AWT and Swing

FlourishingPyramidsOfGiza avatar
FlourishingPyramidsOfGiza
·
·
Download

Start Quiz

Study Flashcards

30 Questions

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.

Component

Class ______ is a subclass of Component.

Container

Any object that is a ______ can be used to organize other Components in a GUI.

Container

Class ______ is the superclass of all lightweight Swing components, all of which are also Containers.

JComponent

Several Swing components are ______ components.

heavyweight

Java allows you to declare classes inside other classes — these are called ______ classes.

nested

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.

inner

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.

inner-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.

nested

Event handlers tend to be specific to the application in which they are defined, so they are often implemented as private ______ classes.

inner

GUI components can generate many ______ in response to user interactions.

events

BorderLayout arranges components into five regions: NORTH, SOUTH, EAST, WEST and ______ .

CENTER

Methods addMouseListener and addMouseMotionListener register ______ and MouseMotionListeners, respectively.

MouseListeners

MouseEvent methods getX and getY return the x- and ycoordinates of the mouse at the time the ______ occurred.

event

An adapter class implements an interface and provides a default implementation (with an empty method body) 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 ______ handling.

event

Many event-listener interfaces contain multiple ______.

methods

Package javax.swing.event contains interface ______ which extends interfaces MouseListener and MouseMotionListener

MouseInputListener

MouseListener and MouseMotionListener methods are called when the ______ interacts with a Component

mouse

Each mouse event-handling method receives a ______ object that contains information about the mouse event

MouseEvent

Coordinates are measured from the upper-left corner of the GUI component on which the event ______

occurred

Interface ______ enables applications to respond to the rotation of a mouse wheel

MouseWheelListener

Class ______ contains methods that enable the event handler to obtain information about the amount of wheel rotation

MouseWheelEvent

The application chooses the number to be guessed by selecting an integer at random in the range 1–______.

1000

The background color should change to either ______ or blue.

red

A JLabel should display either "Too High" or "Too ______" to help the user zero in.

Low

When the user gets the correct answer, "______!" should be displayed.

Correct

A JButton should be provided to allow the user to play the game ______.

again

When the JButton is clicked, a new random number should be generated and the input JTextField changed to be ______.

editable

Study Notes

GUI Components and Events

  • Package javax.swing.event contains interface MouseInputListener, which extends interfaces MouseListener and MouseMotionListener.
  • MouseListener and MouseMotionListener 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 a MouseWheelEvent 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 of Component and is used to organize and display components on the screen.
  • Class JComponent is a subclass of Container 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 and addMouseMotionListener register MouseListeners and MouseMotionListeners, 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.

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.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

More Quizzes Like This

Advance Java Unit 1: JFC and AWT
16 questions

Advance Java Unit 1: JFC and AWT

ProgressiveEmpowerment avatar
ProgressiveEmpowerment
Advanced Java Unit 1: JFC and AWT
16 questions
Use Quizgecko on...
Browser
Browser