Extending a JFrame

composition, inheritance, java, jframe, swing

Solution

You should not extend a class, unless you want to actually extend its functionality, in the example you've shown, you should use option 2, as option 1 is an abuse of the `extend`ing feature.

In other words - as long as the answer to the question is Test a `JFrame`? is NO, it should not extend `JFrame`.

Problem

What are the pros and cons of extending a JFrame rather than create a new JFrame? For example: ``` public class Test extends JFrame { setVisible(true); } ``` or ``` public class Test { JFrame test = new JFrame(): test.setVisible(true); } ```

Original source