/* IntMatrix.java */ import java.io.*; import java.awt.*; class IntMatrix implements DrawingObj { int rows, columns; int[][] elems; /* Drawing characteristics */ int cell_size; Font font = new Font("Courier", Font.PLAIN, 12); //Font boxFont = new Font("Courier", Font.PLAIN, 12); String[] rowLabels, colLabels; String title = null; boolean[][] highlight; boolean[][] highlight2; static final int horizSpace = 32; static final int vertSpace = 17; private Color fg, bg; private int x, y; public IntMatrix( int rows, int columns ) { int j, k; this.rows = rows; this.columns = columns; elems = new int[rows][columns]; highlight = new boolean[rows][columns]; highlight2 = new boolean[rows][columns]; for(j=0; j 4) strs[i] = strs[i].substring(0, 4); if (strs[i].length() < 4) { String blank = new String(); for (int j = 0; j < 4-strs[i].length(); j++) blank = blank.concat(" "); strs[i] = blank + strs[i]; } rowLabels[i] = new String(strs[i]); } } public void setColLabels(String[] strs) { if (strs.length != columns) { System.out.println( "Column labels do no match the number of columns!"); return; } colLabels = new String[columns]; for (int i = 0; i < columns; i++) { if (strs[i].length() > 4) strs[i] = strs[i].substring(0, 4); if (strs[i].length() < 4) { String blank = new String(); for (int j = 0; j < 4-strs[i].length(); j++) blank = blank.concat(" "); strs[i] = blank + strs[i]; } colLabels[i] = new String(strs[i]); } } public void drawBox(Graphics g, int x, int y, String str, Color fg, Color bg, Font font) { g.setColor(bg); g.fillRect(x, y, horizSpace, vertSpace); g.setColor(Color.black); g.drawRect(x, y, horizSpace, vertSpace); g.setColor(fg); g.setFont(font); g.drawString(str, x + 2, y + vertSpace - 4); } public void move(int x, int y) { this.x = x; this.y = y; } public int getX() { return x; } public int getY() { return y; } public void setColor(Color fg, Color bg) { this.fg = fg; this.bg = bg; } public void draw(Graphics g) { drawMatrix(g, x, y, fg, bg); } public void drawMatrix(Graphics g, int x, int y, Color fg, Color bg) { int j, k, elem; int posnX = x, posnY = y; // draw colLabels if (colLabels != null && colLabels.length == columns) { posnX += horizSpace + 2; for (int i = 0; i < columns; i++) { drawBox(g, posnX, posnY, colLabels[i], bg, fg, font); posnX += horizSpace + 2; } } posnX = x; // draw rowLabels if (rowLabels != null && rowLabels.length == rows) { posnY += vertSpace + 2; for (int i = 0; i < rows; i++) { drawBox(g, posnX, posnY, rowLabels[i], bg, fg, font); posnY += vertSpace + 2; } } posnY = y + vertSpace + 2; for(j=0;j 0) { posnY += 5; posnX = x + (columns/2 - 1)*(horizSpace + 2); new ComBox(posnX, posnY, title, Color.black, Color.green, font).draw(g); } } } // class IntMatrix