So I want my main class to extend both JFrame and JPanel. How would I do this?
For example:
public class mainClass extends JFrame {
//code here
}
How would I also extend JPanel for that same class?
Thanks in advance!
How to extend JFrame and JPanel in a main class?
Let me answer you by asking a question:
Can a son have two fathers in a the same time? NO, because we don't know who is the real father, but after DNA testing you know who is the real one.
In java, there is no DNA testing, sorry for that, therefore, multiple inheritance not allowed.
In your case, if the class extended from both JFrame and JPanel, what will be the behavior of this class, panel or frame?
Java does not support multiple inheritance. Possible solutions include coding an inner class in your main class that extends JPanel and then another inner class that extends JFrame. You can also just code two separate (not-inner) classes that extend the respective classes as that is the common approach I would use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With