FileDocCategorySizeDatePackage
MemImage.javaAPI DocExample1547Sat Nov 25 12:55:08 GMT 2000None

MemImage

public class MemImage extends Component
MemImage is an in-memory icon showing a Color gradient.

Fields Summary
private Image
img
The image
private int
w
The image width
private int
h
The image height
Constructors Summary
public MemImage()
Construct a MemImage with a default size

		this(100,100);
	
public MemImage(int w, int h)
Construct a MemImage with a specified width and height

		this.w = w;
        this.h = h;
        int pix[] = new int[w * h];
        int index = 0;
        for (int y = 0; y < h; y++) {
            int red = (y * 255) / (h - 1);
            for (int x = 0; x < w; x++) {
                int blue = (x * 255) / (w - 1);
                pix[index++] = (255 << 24) | (red << 16) | blue;
            }
        }
        img = createImage(new MemoryImageSource(w, h, pix, 0, w));
		setSize(getPreferredSize());
	
Methods Summary
public java.awt.ImagegetImage()
Getter for the Image

		return img;
	
public java.awt.DimensiongetPreferredSize()

		return new Dimension(w, h);
	
public static voidmain(java.lang.String[] av)
Demo main program, showing two ways to use it. Create a small MemImage and set it as this Frame's iconImage. Also display a larger version of the same image in the Frame.

		Frame f = new Frame("MemImage.java");
		f.add(new MemImage());
		f.setIconImage(new MemImage(16,16).getImage());
		f.pack();
		f.setVisible(true);
	
public voidpaint(java.awt.Graphics g)

		g.drawImage(img, 0, 0, getSize().width, getSize().height, this);