import java.awt.*; import java.util.*; public class VisibleVerticalArray extends VisibleArray { private int cellWidth; private int cellHeight = 30; private int indexWidth = 50; public VisibleVerticalArray(String caption, Object a[]) { super(caption, a); } public void paint(Graphics g) { super.paint(g); cellWidth = getSize().width; FontMetrics fm = g.getFontMetrics(); int vOffset = fm.getAscent() + 8; int hOffset1 = 10; int hOffset2 = hOffset1 + indexWidth + 4; g.setFont(new Font("Helvetica", Font.BOLD, (cellHeight * 2)/3)); for (int i = 0; i < length(); i++) { int vPosition1 = (int) ((i + 0.1)*cellHeight) + vOffset + 8; int vPosition2 = vOffset + (cellHeight * (i + 1)); // Show the array index on a green background: g.setColor(Color.green); g.fillRect(4, vPosition1, indexWidth, cellHeight - 4); g.setColor(Color.black); g.drawString( i + "", hOffset1 + 4, vPosition2); // Show the array value on a blue background: g.setColor(Color.blue); g.fillRect(hOffset2, vPosition1, cellWidth - (hOffset2 + 4), cellHeight - 4); g.setColor(Color.red); g.drawString( theArray[i].toString(), hOffset2 + 4, vPosition2); } } public void describeVVA() { System.out.println("A VisibleVerticalArray: "); describe(); } } // S. Tanimoto, November 2000.