aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Whats the point of extending JFrames and JPanels? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Whats the point of extending JFrames and JPanels?" Watch "Whats the point of extending JFrames and JPanels?" New topic
Author

Whats the point of extending JFrames and JPanels?

Bob Zoloman
Ranch Hand

Joined: Jul 02, 2006
Posts: 72
Could someone please explain the purpose of extending a JFrame or JPanel? Also, how do you decide which one to extend? I can't seem to find much information on this subject, thanks.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
In my opinion, it's actually almost always not-so-good practice - I prefer to use composition over inheritance in those cases.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Dave Casman
Greenhorn

Joined: Sep 12, 2006
Posts: 6
Extending JPanel is perfectly reasonable if your purpose is to also override paintComponent(). I think the usual method for providing custom painting/drawing in Swing is to extend JPanel.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Dave Casman:
Extending JPanel is perfectly reasonable if your purpose is to also override paintComponent(). I think the usual method for providing custom painting/drawing in Swing is to extend JPanel.


Ah, yes, that might be true. It's just that I almost never have to do that...
 
 
subject: Whats the point of extending JFrames and JPanels?