黑莓手机:重写paint()方法VS subpaint() [英] BlackBerry: Overriding paint() vs subpaint()

查看:331
本文介绍了黑莓手机:重写paint()方法VS subpaint()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在制作自定义字段,我应该重写的paint() VS subpaint()方法的考虑渲染领域的定制部件?

When making a custom field, what should I consider between overriding the paint() vs subpaint() methods to render custom parts of a field?

我的code目前覆盖的paint(),但我刚刚看了这表明实施 subpaint()方法。在我最简单的自定义字段(如使用渐变填充一个自定义的旗帜),我可以看到的唯一区别是,如果我重写的paint(),那么我必须调用 super.paint(),但如果我重写 subpaint()那么就没有必要调用 super.subpaint()

My code currently overrides paint(), but I just read the javadoc which suggests to implement the subpaint() method. In my very simple custom fields (like a custom banner with gradient fill), the only difference I can see is that if I override paint(), then I must call super.paint(), but if I override subpaint() then there is no need to call super.subpaint().

我认识到,对于更高级的定制,会有一些因素要考虑到,这是很有可能的方法之一可能被视为不良做法。

I realise that for more advanced customisations, there would be some considerations to take into account, and it is highly likely that one of the approaches might be considered poor practice.

我应该改变我的基本方法(和那些在我的公司)选择重写 subpaint()默认的未来?

Should I change my base approach (and those in my company) to choose to override subpaint() by default in the future?

(我希望这不被视为一个问题的讨论 - 那不是我的意图 - 感谢)

(I hope this is not considered a discussion question - that is not my intent - thanks)

推荐答案

subpaint()被真正用于管理者,不一定是自定义字段(是的,管理是一个领域)。它的默认实现是只通过其子域循环,并发出就可以了 paintChild()电话。 的paint(),在另一方面,对于现场做画相关本身。在你的情况,你应该重写的paint()

subpaint() is really used for Managers, not necessarily a custom Field (yeah, Manager is a Field). It's default implementation is to just loop through its child Fields and issue a paintChild() call on it. paint(), on the other hand, is for the Field to do drawing related to itself. In your case, you should be overriding paint().

那么,为什么你重写 subpaint()?你想,如果你需要的孩子田画自己在一个特定的顺序。你说你有一个放在彼此顶部某些字段的自定义管理器。如果他们需要在一定的顺序来画,你会覆盖 subpaint()来确保正确的字段是在上面。此外,经理的的paint()将调用其 subpaint(),有事要记住,如果你覆盖它。

So why would you override subpaint()? You would want to if you need child Fields to paint themselves in a certain order. Say that you have a custom Manager that places some Fields on top of each other. If they need to be painted in a certain order, you would override subpaint() to make sure the right Field is "on top." Also, a Manager's paint() will call its subpaint(), something to keep in mind if you override it.

这篇关于黑莓手机:重写paint()方法VS subpaint()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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