Class Image

public class Image
extends Widget
implements SourcesClickEvents, SourcesMouseEvents, SourcesLoadEvents
A widget that displays the image at a given URL.

CSS Style Rules

Example

public class ImageExample implements EntryPoint {

  private Label lbl = new Label();

  public void onModuleLoad() {
    // Create an image, not yet referencing a URL.
    Image image = new Image();

    // Hook up a load listener, so that we can find out when it loads (or
    // fails to, as the case may be).
    image.addLoadListener(new LoadListener() {
      public void onLoad(Widget sender) {
        lbl.setText("Done loading.");
      }
    
      public void onError(Widget sender) {
        lbl.setText("An error occurred while loading.");
      }
    });

    // Point the image at a real URL.
    lbl.setText("Loading...");
    image.setUrl("http://www.google.com/images/logo.gif");

    // Add the image & label to the root panel.
    VerticalPanel panel = new VerticalPanel();
    panel.add(lbl);
    panel.add(image);
    RootPanel.get().add(panel);
  }
}

Constructors

Image()Creates an empty image.
Image(String)Creates an image with a specified URL.

Methods

addClickListener(ClickListener)Adds a listener interface to receive click events.
addLoadListener(LoadListener)Adds a listener interface to receive load events.
addMouseListener(MouseListener)Adds a listener interface to receive mouse events.
getUrl()Gets the URL of the image.
onBrowserEvent(Event)
prefetch(String)Causes the browser to pre-fetch the image at a given URL.
removeClickListener(ClickListener)Removes a previously added listener interface.
removeLoadListener(LoadListener)Removes a previously added listener interface.
removeMouseListener(MouseListener)Removes a previously added listener interface.
setUrl(String)Sets the URL of the image to be displayed.

Constructor Detail

Image

public Image()
Creates an empty image.

Image

public Image(String url)
Creates an image with a specified URL.

Parameters

url
the URL of the image to be displayed

Method Detail

addClickListener

public void addClickListener(ClickListener listener)
Adds a listener interface to receive click events.

Parameters

listener
the listener interface to add

addLoadListener

public void addLoadListener(LoadListener listener)
Adds a listener interface to receive load events.

Parameters

listener
the listener interface to add

addMouseListener

public void addMouseListener(MouseListener listener)
Adds a listener interface to receive mouse events.

Parameters

listener
the listener interface to add

getUrl

public String getUrl()
Gets the URL of the image.

Return Value

the image URL

onBrowserEvent

public void onBrowserEvent(Event event)

Parameters

event

prefetch

public static void prefetch(String url)
Causes the browser to pre-fetch the image at a given URL.

Parameters

url
the URL of the image to be prefetched

removeClickListener

public void removeClickListener(ClickListener listener)
Removes a previously added listener interface.

Parameters

listener
the listener interface to remove

removeLoadListener

public void removeLoadListener(LoadListener listener)
Removes a previously added listener interface.

Parameters

listener
the listener interface to remove

removeMouseListener

public void removeMouseListener(MouseListener listener)
Removes a previously added listener interface.

Parameters

listener
the listener interface to remove

setUrl

public void setUrl(String url)
Sets the URL of the image to be displayed.

Parameters

url
the image URL