Why can I not call add() on a JFrame and instead must call it on a Container?

jitenderk

New Member
I am reading Head First Java. When introducing GUIs (page 354 for those of you who have the book), the author writes:\[code\]frame.getContentPane().add(button);\[/code\]\[quote\] "You don't add things to the frame directly. Think of the frame as the trim around the window, and you add things to the window pane."\[/quote\]After looking at the Java API entry for JFrame, I saw that JFrame is a subclass of Component and inherits the add(Component) from Component, so it would work to simply write:\[code\]frame.add(button);\[/code\]Why does the book recommend to use frame.getContentPane.add(button)?Thanks in advance!
 
Top