简体   繁体   English

AWT中Canvas的用途是什么?

[英]What is the use of Canvas in AWT?

I've been searching many sources yet I still cannot find a decent explanation. 我一直在搜索许多资源,但仍然找不到合适的解释。 Why should I use it, what is its' purpose and why does it differ from JPanels and such? 我为什么要使用它,它的目的是什么?为什么它与JPanels等不同?

From my understanding, Canvas is just the AWT version of Swing's JComponent. 据我了解, Canvas只是Swing JComponent的AWT版本。 You shouldn't use it directly, unless you're making a pure AWT app. 除非您要制作纯AWT应用程序,否则不应该直接使用它。 You can find more info here . 您可以在此处找到更多信息

The speciality of Canvas is that, like Window, it can provide customized hardware-accelerated double-buffering and page-flipping. Canvas的特长是,与Window一样,它可以提供定制的硬件加速的双缓冲和页面翻转。 See BufferStrategy . 参见BufferStrategy

A canvas is for drawing on, basically. 基本上,画布是用于绘图的。 It also serves like a Panel for creating a custom AWT-based component, but unlike Panel it can't contain other components. 它也像Panel一样,用于创建基于AWT的自定义组件,但是与Panel不同,它不能包含其他组件。

public class Canvas
extends Component
implements Accessible

A Canvas component represents a blank rectangular area of the screen onto which the application can draw or from which the application can trap input events from the user. 画布组件代表屏幕的空白矩形区域,应用程序可以在该区域上进行绘制,或者应用程序可以从该区域捕获来自用户的输入事件。 An application must subclass the Canvas class in order to get useful functionality such as creating a custom component. 为了获得有用的功能(例如创建自定义组件),应用程序必须将Canvas类子类化。 The paint method must be overridden in order to perform custom graphics on the canvas. 必须重写paint方法,以便在画布上执行自定义图形。

A canvas is for drawing on, basically. 基本上,画布是用于绘图的。 It also serves like a Panel for creating a custom AWT-based component, but unlike Panel it can't contain other components. 它也像Panel一样,用于创建基于AWT的自定义组件,但是与Panel不同,它不能包含其他组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM