使用paintComponent()和paint()的Java自定义绘图 [英] Java custom drawing with paintComponent() and paint()

查看:75
本文介绍了使用paintComponent()和paint()的Java自定义绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来自Objective-C背景,并且多年来一直在iOS和Mac OS平台上进行开发.我喜欢自定义绘图的概念,因此我想复制我在上述平台上所做的工作.

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. I love the concept of custom drawing and therefore I would like to replicate what had been done by me on the aforementioned platform.

在iOS中,我将调用 -drawRect()绘制自定义视图,然后,我可以继续在该图的顶部添加其他可视组件.我知道在java swing和awt中有等效项,称为 paint() paintComponent().但是,我不太确定图纸是如何进行的.我不知道何时调用super方法(开始还是结束?)以及如何将其他组件添加到自定义绘制的组件中(自定义绘制有时出现在顶部,有时出现在下方).

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. I know that there are equivalents in java swing and awt called paint() and 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).

有人可以阐明这一点吗?

Can someone shed some light on this ?

我已经阅读了何时使用的内容,但是我仍然不是100%地确定,因此任何人都可以解释何时确切使用 paint()和何时使用 paintComponent()吗?

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() ?

推荐答案

从Java教程开始.

http://docs.oracle.com/javase/tutorial/uiswing/painting/index.html

这篇关于使用paintComponent()和paint()的Java自定义绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆