aspose file tools*
The moose likes Beginning Java and the fly likes Extend in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Extend in Java" Watch "Extend in Java" New topic
Author

Extend in Java

Florin Florentin
Ranch Hand

Joined: May 12, 2009
Posts: 43


Hello.

I know it is not possible to extend two classes in Java. I want to ask you what trick can i do to extend Observable on a Form(who extends javax.swing.JFrame) ?

thank you
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Florin Florentin wrote:I know it is not possible to extend two classes in Java.

Yep. Java doesn't allow multiple inheritance, and for good reason.

I want to ask you what trick can i do to extend Observable on a Form(who extends javax.swing.JFrame) ?

1) In most situations, you shouldn't subclass JFrame. Instead have your GUI programs create a JPanel, and then when you are ready to view the main app, create the JFrame on the fly and place your JPanel into the JFrame's contentPane. Usually it is unnecessary to subclass JPanel but instead extend your classes through composition rather than inheritance (google these terms for some interesting articles).
2) Also, you could just not use Java's ready-made Observer/Observable classes/interfaces and instead roll your own. They're super easy to make and educational too.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Extend in Java