简体   繁体   English

使用paintComponent()和paint()进行Java自定义绘图

[英]Java custom drawing with paintComponent() and paint()

I come from an Objective-C background and I have been developing on the iOS and Mac OS platform for a number of years now. 我来自Objective-C背景,我已经在iOS和Mac OS平台上开发了很多年了。 I love the concept of custom drawing and therefore I would like to replicate what had been done by me on the aforementioned platform. 我喜欢自定义绘图的概念,因此我希望复制我在上述平台上所做的工作。

In iOS I would call -drawRect() to draw a custom view and then, I could go ahead and add other visual components on top of that drawing. 在iOS中,我会调用-drawRect()来绘制自定义视图,然后,我可以继续在该绘图的顶部添加其他可视组件。 I know that there are equivalents in java swing and awt called paint() and paintComponent() . 我知道java swing和awt中有等价的叫paint()paintComponent() However, I am not quite sure how the drawing goes about. 但是,我不太确定绘图是如何进行的。 I do not know when to call the super method (beginning or end ?) and how to add other components to the custom drawn component (custom drawing sometimes appears on top, sometimes beneath). 我不知道何时调用super方法(开始或结束?)以及如何将其他组件添加到自定义绘制组件(自定义绘图有时会显示在顶部,有时显示在下方)。

Can someone shed some light on this ? 有人可以对此有所了解吗?

I have already read up a little bit on when to use what, but I am still not 100% sure, so can anybody explain when exactly to use paint() and when paintComponent() ? 我已经阅读了一些关于什么时候使用什么的内容,但我仍然不是100%肯定,所以任何人都可以解释什么时候使用paint()paintComponent()

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

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