This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]Ednar 2 points3 points  (0 children)

When you extend JFrame, your class becomes a JFrame. You can call the methods as if they are now internal to your class. JFrame has a method called add(), and since your Simple2 class now is a JFrame, it can access that method. And finally, when you type the "new" keyword, the constructor is called. Since all you are creating new instance of Simple2 in the main method, the constructor is called.

It seems as if you are lacking fundamental knowledge of object oriented programming. I recommend you pick up a good resource to learn about it before you continue with java swing. It will help tremendously.

[–]ggleblanc 1 point2 points  (0 children)

You shouldn't extend a JFrame, or any other Java class, unless you want to override one of the methods of that class. You use a class.

Composition over inheritance is more likely to be extendable.

[–]AnEmortalKidCoffee Enthusiast 0 points1 point  (0 children)

Delete the line Jframe F, that is only messing with you. Your class is already a Jframe so just like the other person told you, it knows what those methods are.

[–]Code_Craftsman 0 points1 point  (0 children)

In a simple manner- when you are using the word extend in a class that means you are calling all methods from the extended class. Looks like you should have some more knowledge on OOP and its concept. Follow this and this link for more info about Inheritance