java - Correct way to create a JFrame -
this question has reply here:
extends jframe vs. creating within the program 6 answersi reading 2 ways of creating jframe , don't undersand improve or differences:
import java.awt.*; import javax.swing.*; public class myframepanel { public static void main(string[] args) { jframe myframe = new jframe("myframepanel"); ....
and 1 find in books:
import java.awt.*; import javax.swing.*; public class buttonframe **extends jframe**{ public buttonframe() { super("button frame"); setdefaultcloseoperation(jframe.exit_on_close); ... setvisible(true); } public static void main(string[] args) { buttonframe bf = new buttonframe(); } }
i going utilize first 1 -i found in stackoverflow- wonder why of books reading java using "extends jframe" one.
thank much , sorry bothering if question stupid.
the first 1 choice. think composition on inheritance.
to favor composition on inheritance design principle gives design higher flexibility, giving business-domain classes , more stable business domain in long term.
if won't utilize myframepanel
within jframe
, instead in applet
, it's easier switch , improve maintain in long term.
java swing jframe
No comments:
Post a Comment