Roughian Examples Site Map - Examples - Tutorials

LoadListener


Version 1.0 onwards

Tells You What Happened When You Tried To Load An Image



Sources



This is a listener only used for the Image widget.

It fires onError(Widget sender) if the image fails to load, and onLoad(Widget sender) if it loads successfully

Note that the image MUST be attached to the DOM before the load starts. You can't try to load the image and add it in the onLoad(Widget sender) event or add a message if it fails.

There are two demos in the code: the first will succeed, the second will fail.


Code


    class Demo1 extends Composite implements LoadListener
    {
        SimplePanel holder = new SimplePanel();
        final Image image;
        public Demo1()
        {
            initWidget(holder);
            holder.add(image = new Image());
            image.addLoadListener(this);
            image.setUrl("img/IanBambury.jpg");
        }
        public void onError(Widget sender)
        {
            holder.clear();
            holder.add(new Label("Image Failed To Load in Demo 1"));
        }
        public void onLoad(Widget sender)
        {
        }
    }
    class Demo2 extends Composite implements LoadListener
    {
        SimplePanel holder = new SimplePanel();
        final Image image;
        public Demo2()
        {
            initWidget(holder);
            holder.add(image = new Image());
            image.addLoadListener(this);
            image.setUrl("img/DoesNotExist.jpg");
        }
        public void onError(Widget sender)
        {
            holder.clear();
            holder.add(new Label("Image Failed To Load in Demo 2"));
        }
        public void onLoad(Widget sender)
        {
        }
    }