Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to create JFrame [closed]

Tags:

java

swing

jframe

Which is the best way to create a JFrame and handle it?

  1. Create a class and inside it create an object JFrame
  2. Inherit from JFrame like class MyClass extends JFrame
like image 470
eng_mazzy Avatar asked Feb 12 '12 11:02

eng_mazzy


2 Answers

Whenever possible, do not use inheritance (your class is-a JFrame) but choose composition (e.g. your class has-a JFrame). It's a common design principle.

And it doesn't have any significant impact on performance.

like image 101
Andreas Dolk Avatar answered Oct 17 '22 09:10

Andreas Dolk


Basically, the only times you should extend JFrame is if you need to overload any methods in it.

That being said, there shouldn't be any noticeable performance hit one way or the other.

like image 22
Josh Claxton Avatar answered Oct 17 '22 08:10

Josh Claxton