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) ?
posted 6 years ago
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.