e558. Multi-image interactive display in applets

Source: Internet
Author: User

This is the simplest applet to animate an array of images. In the practice, you should the use of double-buffering (which this example does isn't use ) to eliminate flickering.

Import java.applet.*;        Import java.awt.*; public classAnimappletExtends Applet implements Runnable {image[] images = new image[2];        int frame = 0;            volatile thread thread; public void init () {images[0] = GetImage (Getdocumentbase (),"Http://hostname/image0.gif"); IMAGES[1] = GetImage (Getdocumentbase (),"Http://hostname/image1.gif");        public void Start () {(thread = new Thread (this)). Start ();        } public void Stop () {thread = null; } public void Paint (Graphics g) {g.drawimage (Images[frame],0,0, this); } public void Run () {int delay = +; 1 second try {while (thread = = Thread.CurrentThread ()) {frame = (frame+1                    )%images.length;                    Repaint ();                Thread.Sleep (delay); }} catch (Exception e) {}}}

related Examples

e558. Multi-image interactive display in applets

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.