MemImagepublic class MemImage extends Component MemImage is an in-memory icon showing a Color gradient. |
Fields Summary |
---|
private Image | imgThe image | private int | wThe image width | private int | hThe 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.Image | getImage()Getter for the Image
return img;
| public java.awt.Dimension | getPreferredSize()
return new Dimension(w, h);
| public static void | main(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 void | paint(java.awt.Graphics g)
g.drawImage(img, 0, 0, getSize().width, getSize().height, this);
|
|