油漆()如何工作 [英] how does paint() work

查看:28
本文介绍了油漆()如何工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能简单地告诉我java小程序中的paint()方法究竟是如何工作的?比如,它什么时候被调用,它将如何被调用?因为有时它会被多次调用,我不知道这是怎么发生的.

Can anyone tell me exactly how does the paint() method in java applet work, in simple words? Like, when it will be called , how it will be called? Because sometimes it gets called multiple times and I do not know how that happens.

推荐答案

要理解这一点,您需要了解 Applet Lifecycle..

To understand this you need to know Applet Lifecycle..

Applet 的生命周期:

Life Cycle of an Applet:

Applet 类中的四个方法为您提供了构建任何严肃小程序的框架:

Four methods in the Applet class give you the framework on which you build any serious applet:

1) init:此方法用于小程序所需的任何初始化.在applet标签内的param标签处理完毕后调用.

1) init: This method is intended for whatever initialization is needed for your applet. It is called after the param tags inside the applet tag have been processed.

2) start:浏览器调用init方法后自动调用该方法.每当用户在转到其他页面后返回包含小程序的页面时,也会调用它.

2) start: This method is automatically called after the browser calls the init method. It is also called whenever the user returns to the page containing the applet after having gone off to other pages.

3) stop:当用户离开小程序所在的页面时,会自动调用此方法.因此,它可以在同一个小程序中重复调用.

3) stop: This method is automatically called when the user moves off the page on which the applet sits. It can, therefore, be called repeatedly in the same applet.

4) destroy:只有在浏览器正常关闭时才会调用该方法.由于小应用程序旨在存在于 HTML 页面上,因此您通常不应在用户离开包含小应用程序的页面后留下资源.

4) destroy: This method is only called when the browser shuts down normally. Because applets are meant to live on an HTML page, you should not normally leave resources behind after a user leaves the page that contains the applet.

5) paint:在 start() 方法之后立即调用,也可以在小程序需要在浏览器中重新绘制自身时调用.Paint() 方法实际上是从 java.awt 继承的.

第二种情况,paint() 调用是在程序调用 repaint() 或 update() 时产生的.repaint() 方法是由程序调用以进行绘图的方法.他们是这种方法的 4 个版本,但通常使用没有参数的版本.通过 repaint() 绘制最常发生在响应用户输入.

The second case, when paint() calls are genereted is when the program calls repaint() or update(). The repaint() method is the one invoked by a program to do drawing. Their are 4 versions of this method but the one with no arguments is usually used. Drawing via repaint() most often takes place in response to user input.

repaint() ==> update() ==(通常调用)==>paint()

repaint() 不直接调用paint().它调度对中间方法 update() 的调用.最后,update() 调用paint()(除非您覆盖update).

repaint() does not invoke paint() directly. It schedules a call to an intermediate method, update(). Finally, update() calls paint() (unless you override update).

这篇关于油漆()如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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