Пример #1
0
  public void paintComponent(Graphics g) throws RuntimeException {
    int squarewidth = getSquareWidth();
    int squareheight = getSquareHeight();

    int hoffset = getHorizontalOffset();
    int voffset = getVerticalOffset();

    for (int x = 0; x < grid.maxX(); x++) {
      for (int y = 0; y < grid.maxY(); y++) {
        Cell tmp = grid.grabObjectAt(x, y);

        if (tmp == null) {
          g.setColor(Color.gray.darker());
        } else {
          g.setColor(tmp.getColor());
        }

        g.fillRect(
            hoffset + x * squarewidth,
            voffset + ((grid.maxY() - y) * squareheight),
            squarewidth - 1,
            squareheight - 1);
      }
    }
  }
Пример #2
0
  protected int getSquareWidth() {
    int swidth = getRealWidth() / (grid.maxX() + 1);

    if (swidth > 0) {
      return swidth;
    } else {
      return 1;
    }
  }
Пример #3
0
 protected int getHorizontalOffset() {
   int offset = (getRealWidth() - (getSquareWidth() * (grid.maxX()))) / 2;
   return offset;
 }