Java tutorial
// IconLine // Copyright (C) by Andrea Carboni. // This file may be distributed under the terms of the LGPL license. // import java.awt.Component; import java.awt.Graphics; import java.awt.Image; import java.util.Vector; import javax.swing.Icon; // public class IconLine implements Icon { private int iWidth = 0; private int iHeight = 0; private int iSpace = 1; private Vector vImages = new Vector(); //--------------------------------------------------------------------------- //--- //--- Constructor //--- //--------------------------------------------------------------------------- public IconLine() { } //--------------------------------------------------------------------------- public IconLine(int space) { iSpace = space; } //--------------------------------------------------------------------------- //--- //--- Constructor //--- //--------------------------------------------------------------------------- public void addImage(Image image) { vImages.add(image); iWidth = iWidth + image.getWidth(null); iHeight = image.getHeight(null); } //--------------------------------------------------------------------------- public void setImage(int index, Image image) { vImages.set(index, image); iHeight = image.getHeight(null); } //--------------------------------------------------------------------------- //--- //--- Icon interface methods //--- //--------------------------------------------------------------------------- public int getIconWidth() { return iWidth; } //--------------------------------------------------------------------------- public int getIconHeight() { return iHeight; } //--------------------------------------------------------------------------- public void paintIcon(Component c, Graphics g, int x, int y) { int dx = 0; for (int i = 0; i < vImages.size(); i++) { Image image = (Image) vImages.get(i); g.drawImage(image, x + dx, y, c); dx += image.getWidth(c) + iSpace; } } } //