JPanel、JFrame、JComponent 和 JApplet 之间的区别

Difference between JPanel, JFrame, JComponent, and JApplet(JPanel、JFrame、JComponent 和 JApplet 之间的区别)

本文介绍了JPanel、JFrame、JComponent 和 JApplet 之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个有趣的物理模拟器,当我试图找出所有这些 J 之间的区别时,我正在查找图形教程.有人可以详细说明它们,或者提供指向有用来源的链接吗?

I'm making a physics simulator for fun and I was looking up graphics tutorials when I tried to figure out the difference between all these J's. Can somebody elaborate on them or perhaps provide a link to a helpful source?

推荐答案

这些类是 Java UI 设计的常见扩展点.首先,要意识到他们之间不一定有直接的关系,所以试图找到他们之间的关系可能会适得其反.

Those classes are common extension points for Java UI designs. First off, realize that they don't necessarily have much to do with each other directly, so trying to find a relationship between them might be counterproductive.

JApplet - 一个基类,可让您编写将在浏览器上下文中运行的代码,例如交互式网页.这很酷,但它带来了局限性,这是它在现实世界中表现出色的代价.当您想在网页中拥有自己的 UI 时,通常会使用 JApplet.我一直想知道为什么人们不利用小程序来存储会话状态,因此不需要数据库或 cookie.

JApplet - A base class that let's you write code that will run within the context of a browser, like for an interactive web page. This is cool and all but it brings limitations which is the price for it playing nice in the real world. Normally JApplet is used when you want to have your own UI in a web page. I've always wondered why people don't take advantage of applets to store state for a session so no database or cookies are needed.

JComponent - 打算与 Swing 交互的对象的基类.

JComponent - A base class for objects which intend to interact with Swing.

JFrame - 用来表示一个窗口应该有的东西.这包括边框(可调整大小的y/n?)、标题栏(应用程序名称或其他消息)、控件(允许最小化/最大化?)和各种系统事件的事件处理程序,如窗口关闭"(允许应用程序退出吗?).

JFrame - Used to represent the stuff a window should have. This includes borders (resizeable y/n?), titlebar (App name or other message), controls (minimize/maximize allowed?), and event handlers for various system events like 'window close' (permit app to exit yet?).

JPanel - 用于将其他元素聚集在一起的通用类.这对于使用可视布局或提供的布局管理器之一更为重要,例如gridbaglayout 等.例如,您有一个比您保留的区域大的文本框.将文本框放在滚动窗格中,然后将该窗格放入 JPanel.那么当你放置JPanel时,它在布局方面会更易于管理.

JPanel - Generic class used to gather other elements together. This is more important with working with the visual layout or one of the provided layout managers e.g. gridbaglayout, etc. For example, you have a textbox that is bigger then the area you have reserved. Put the textbox in a scrolling pane and put that pane into a JPanel. Then when you place the JPanel, it will be more manageable in terms of layout.

这篇关于JPanel、JFrame、JComponent 和 JApplet 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:JPanel、JFrame、JComponent 和 JApplet 之间的区别

基础教程推荐