Class Image
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
Methods
Constructor Detail
Image
public Image()
Creates an empty image.
Image
Creates an image with a specified URL.
Parameters
- url
- the URL of the image to be displayed
Method Detail
addClickListener
Adds a listener interface to receive click events.
Parameters
- listener
- the listener interface to add
addLoadListener
Adds a listener interface to receive load events.
Parameters
- listener
- the listener interface to add
addMouseListener
Adds a listener interface to receive mouse events.
Parameters
- listener
- the listener interface to add
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
Removes a previously added listener interface.
Parameters
- listener
- the listener interface to remove
removeLoadListener
Removes a previously added listener interface.
Parameters
- listener
- the listener interface to remove
removeMouseListener
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