Class ImageCanvas
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Canvas
|
+----ImageCanvas
- public class ImageCanvas
- extends Canvas
A canvas that displays an image.
In effect, ImageCanvas makes an Image into a Component.
Based on class ImageCanvas from "Graphic Java 1.1" p. 262.
Java 1.1 Implementation
- See Also:
- Canvas
-
ImageCanvas(Image)
- Straightforward constructor.
-
getImage()
- Return the image.
-
getPreferredSize()
- The preferred size is the image size.
-
imageUpdate(Image, int, int, int, int, int)
- The callback function for image updates.
-
paint(Graphics)
-
-
update(Graphics)
- Update the display screen.
ImageCanvas
public ImageCanvas(Image image)
- Straightforward constructor.
It starts loading the image if it has not already been started.
The constructor waits for the image size to be loaded and sets
the component size to the image size.
- Parameters:
- image - the image to display.
getImage
public Image getImage()
- Return the image.
- Returns:
- the image.
getPreferredSize
public Dimension getPreferredSize()
- The preferred size is the image size.
This method is called by some LayoutManager's, for example, FlowLayout.
The default preferred and default minimum Canvas sizes sre zero;
so this method should be overriden.
By the Archimedian Property, there exists an image such that any
fraction of it is bigger than a reasonably sized Container;
so the default minimum Canvas size of zero is best, and
the method getMinimumSize() is not overriden.
- Returns:
- the image size.
- Overrides:
- getPreferredSize in class Component
- See Also:
- LayoutManager, Dimension
imageUpdate
public boolean imageUpdate(Image i,
int infoflags,
int x,
int y,
int width,
int height)
- The callback function for image updates.
When the image size is already available this method does the default
action of repainting the screen.
If the image size is not available yet then the info flags are tested
and a synchronized code block may be executed to modify
the object state.
- Returns:
- true if further updates are requested.
- Overrides:
- imageUpdate in class Component
- See Also:
- waitForImageSize, ImageObserver
paint
public void paint(Graphics g)
- Overrides:
- paint in class Canvas
update
public void update(Graphics g)
- Update the display screen.
Modified from the default action to eliminate screen flicker.
- Overrides:
- update in class Component