17.3. Components and Containers
A component represents a graphical entity of one kind or another that can be displayed on the screen. A component is any object of a class that is a subclass of Component. As you have seen, a JFrame window is a component, but there are many others. Before getting into specifics, let's first get a feel for the general relationship between the groups of classes that represent components. Part of the class hierarchy with Component as a base is shown in Figure 17-6. The arrows in the diagram point toward the superclass.
Figure 17.6. Figure 17-6
![](/api/v2/epubs/9780764568749/files/9780764568749_components_and_containers_image01.png)
This shows some of the subclasses of Component—the ones that are important to you at the moment. I discussed the chain through to JFrame earlier, but the other branches are new. The classes that you'll be using directly are all the most commonly derived classes.
Let's summarize how you would typically use the key classes in this hierarchy:
Class | Use |
---|---|
JFrame | This is used as the basic Java application window. An object of this class has a title bar and provision for adding a menu. You can also add other components to it. You will usually subclass this class to create a window class specific to your application. You'll then be able to add GUI components or draw in this window if required, as you'll see. |
JWindow | An object of this class type is a window with no title bar or window management icons. One typical use for ... |
Get Ivor Horton's Beginning Java™ 2, JDK™ 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.