扩展JFrame [英] Extending a JFrame
本文介绍了扩展JFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
扩展JFrame 的优缺点是什么,而不是创建新的JFrame ?
What are the pros and cons of extending a JFrame rather than create a new JFrame?
示例:
public class Test extends JFrame {
setVisible(true);
}
或
public class Test {
JFrame test = new JFrame():
test.setVisible(true);
}
推荐答案
你应该不扩展类,除非你想实际扩展它的功能,在你所示的例子中,你应该使用选项2,因为选项1是滥用 extend
功能。
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.
换句话说 - 只要问题的答案是测试 JFrame
? 否,它不应该扩展 JFrame
。
In other words - as long as the answer to the question is Test a JFrame
? is NO, it should not extend JFrame
.
这篇关于扩展JFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文