Why do we need to extend JFrame in a swing application?

前端 未结 4 1052
悲&欢浪女
悲&欢浪女 2020-12-01 22:11

Why do we need to extend the JFrame class when building a Swing application. As far as I know extends is used for inheriting the base class. None o

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-01 22:48

    If you want to create a standalone application, you can either extend JPanel or JFrame or create their instance in your class implementation.

    As a rule, a standalone application with a Swing-based GUI has at least one containment hierarchy with a JFrame as its root. For example, if an application has one main window and two dialogs, then the application has three containment hierarchies, and thus three top-level containers. http://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html?

    http://docs.oracle.com/javase/tutorial/uiswing/components/frame.html

提交回复
热议问题