Containers hold Component References

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

The call to the superclass constructor must be the first statement in the MyFrame constructor.

Containers hold Component References

MyFrame is a Container, because it inherits from JFrame, so GUI components can be added to it. When a component is added to a container, a reference to the component is added to the list of components in the container.

Graphically, the components added to a container appear within the rectangle on the monitor allocated to the container. In the example program, the JLabel is added to the frame, and so appears within that area.

QUESTION 12:

Could additional JLabel references be added to MyFrame?