Java The Complete Reference, Seventh Edition

(Greg DeLong) #1

774 Part II: The Java Library


PlugInFilter.java
PlugInFilteris a simple interface used to abstract image filtering. It has only one method,
filter( ), which takes the applet and the source image and returns a new image that has
been filtered in some way.

interface PlugInFilter {
java.awt.Image filter(java.applet.Applet a, java.awt.Image in);
}

LoadedImage.java
LoadedImageis a convenient subclass ofCanvas, which takes an image at construction time
and synchronously loads it usingMediaTracker.LoadedImagethen behaves properly inside of
LayoutManagercontrol, because it overrides thegetPreferredSize( )andgetMinimumSize( )
methods. Also, it has a method calledset( )that can be used to set a newImageto be displayed
in thisCanvas. That is how the filtered image is displayed after the plug-in is finished.

import java.awt.*;

public class LoadedImage extends Canvas {
Image img;

public LoadedImage(Image i) {
set(i);
}

void set(Image i) {
MediaTracker mt = new MediaTracker(this);

FIGURE 25-7

Sample normal
output from
ImageFilterDemo
Free download pdf