Extending a JFrame

Anonymous181 picture Anonymous181 · May 4, 2012 · Viewed 8.6k times · Source

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);

}

Answer

MByD picture MByD · May 4, 2012

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 extending feature.

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