コード例 #1
0
  public TicTacToeView(int x, int y, int w, int h, TicTacToeModel model) {
    // constructor method

    container = new Rectangle(x, y, w, h);
    container.setBackground(Color.black);
    container.setBounds(x, y, w, h);
    getSmallBox(x, y, w, h);
    modelChanged();
    this.model = model;
  }
コード例 #2
0
  public void getSmallBox(int x, int y, int w, int h) {
    // create 9 small boxes

    cross = new Rectangle(x, y, w, h);
    cross.setBackground(Color.blue);

    circle = new Oval(x, y, w, h);
    circle.setBackground(Color.red);

    smallBox0 = new Rectangle(x, y, w / 3, h / 3);
    smallBox0.setBackground(Color.white);
    container.add(smallBox0);
    smallBox0.add(cross);
    cross.setVisible(setVisibility());
    smallBox0.add(circle);
    circle.setVisible(setVisibility());

    smallBox1 = new Rectangle(x + (w / 3), y, w / 3, h / 3);
    smallBox1.setBackground(Color.white);
    container.add(smallBox1);
    smallBox1.add(cross);
    cross.setVisible(setVisibility());
    smallBox1.add(circle);
    circle.setVisible(setVisibility());

    smallBox2 = new Rectangle(x + (2 * w / 3), y, w / 3, h / 3);
    smallBox2.setBackground(Color.white);
    container.add(smallBox2);
    smallBox2.add(cross);
    cross.setVisible(setVisibility());
    smallBox2.add(circle);
    circle.setVisible(setVisibility());

    smallBox3 = new Rectangle(x, y + (h / 3), w / 3, h / 3);
    smallBox3.setBackground(Color.white);
    container.add(smallBox3);
    smallBox3.add(cross);
    cross.setVisible(setVisibility());
    smallBox3.add(circle);
    circle.setVisible(setVisibility());

    smallBox4 = new Rectangle(x + (w / 3), y + (h / 3), w / 3, h / 3);
    smallBox4.setBackground(Color.white);
    container.add(smallBox4);
    smallBox4.add(cross);
    cross.setVisible(setVisibility());
    smallBox4.add(circle);
    circle.setVisible(setVisibility());

    smallBox5 = new Rectangle(x + (2 * w / 3), y + (h / 3), w / 3, h / 3);
    smallBox5.setBackground(Color.white);
    container.add(smallBox5);
    smallBox5.add(cross);
    cross.setVisible(setVisibility());
    smallBox5.add(circle);
    circle.setVisible(setVisibility());

    smallBox6 = new Rectangle(x, y + (2 * h / 3), w / 3, h / 3);
    smallBox6.setBackground(Color.white);
    container.add(smallBox6);
    smallBox6.add(cross);
    cross.setVisible(setVisibility());
    smallBox6.add(circle);
    circle.setVisible(setVisibility());

    smallBox7 = new Rectangle(x + (w / 3), y + (2 * h / 3), w / 3, h / 3);
    smallBox7.setBackground(Color.white);
    container.add(smallBox7);
    smallBox7.add(cross);
    cross.setVisible(setVisibility());
    smallBox7.add(circle);
    circle.setVisible(setVisibility());

    smallBox8 = new Rectangle(x + (2 * w / 3), y + (2 * h / 3), w / 3, h / 3);
    smallBox8.setBackground(Color.white);
    container.add(smallBox8);
    smallBox8.add(cross);
    cross.setVisible(setVisibility());
    smallBox8.add(circle);
    circle.setVisible(setVisibility());
  }
コード例 #3
0
    public void paint(Graphics g) {

      if (big == null) {
        return;
      }

      big.setBackground(getBackground());
      big.clearRect(0, 0, w, h);

      float freeMemory = (float) r.freeMemory();
      float totalMemory = (float) r.totalMemory();

      // .. Draw allocated and used strings ..
      big.setColor(GREEN);
      big.drawString(
          String.valueOf((int) totalMemory / 1024) + "K allocated", 4.0f, (float) ascent + 0.5f);
      usedStr = String.valueOf(((int) (totalMemory - freeMemory)) / 1024) + "K used";
      big.drawString(usedStr, 4, h - descent);

      // Calculate remaining size
      float ssH = ascent + descent;
      float remainingHeight = (float) (h - (ssH * 2) - 0.5f);
      float blockHeight = remainingHeight / 10;
      float blockWidth = 20.0f;
      float remainingWidth = (float) (w - blockWidth - 10);

      // .. Memory Free ..
      big.setColor(mfColor);
      int MemUsage = (int) ((freeMemory / totalMemory) * 10);
      int i = 0;
      for (; i < MemUsage; i++) {
        mfRect.setRect(5, (float) ssH + i * blockHeight, blockWidth, (float) blockHeight - 1);
        big.fill(mfRect);
      }

      // .. Memory Used ..
      big.setColor(GREEN);
      for (; i < 10; i++) {
        muRect.setRect(5, (float) ssH + i * blockHeight, blockWidth, (float) blockHeight - 1);
        big.fill(muRect);
      }

      // .. Draw History Graph ..
      big.setColor(graphColor);
      int graphX = 30;
      int graphY = (int) ssH;
      int graphW = w - graphX - 5;
      int graphH = (int) remainingHeight;
      graphOutlineRect.setRect(graphX, graphY, graphW, graphH);
      big.draw(graphOutlineRect);

      int graphRow = graphH / 10;

      // .. Draw row ..
      for (int j = graphY; j <= graphH + graphY; j += graphRow) {
        graphLine.setLine(graphX, j, graphX + graphW, j);
        big.draw(graphLine);
      }

      // .. Draw animated column movement ..
      int graphColumn = graphW / 15;

      if (columnInc == 0) {
        columnInc = graphColumn;
      }

      for (int j = graphX + columnInc; j < graphW + graphX; j += graphColumn) {
        graphLine.setLine(j, graphY, j, graphY + graphH);
        big.draw(graphLine);
      }

      --columnInc;

      if (pts == null) {
        pts = new int[graphW];
        ptNum = 0;
      } else if (pts.length != graphW) {
        int tmp[] = null;
        if (ptNum < graphW) {
          tmp = new int[ptNum];
          System.arraycopy(pts, 0, tmp, 0, tmp.length);
        } else {
          tmp = new int[graphW];
          System.arraycopy(pts, pts.length - tmp.length, tmp, 0, tmp.length);
          ptNum = tmp.length - 2;
        }
        pts = new int[graphW];
        System.arraycopy(tmp, 0, pts, 0, tmp.length);
      } else {
        big.setColor(YELLOW);
        pts[ptNum] = (int) (graphY + graphH * (freeMemory / totalMemory));
        for (int j = graphX + graphW - ptNum, k = 0; k < ptNum; k++, j++) {
          if (k != 0) {
            if (pts[k] != pts[k - 1]) {
              big.drawLine(j - 1, pts[k - 1], j, pts[k]);
            } else {
              big.fillRect(j, pts[k], 1, 1);
            }
          }
        }
        if (ptNum + 2 == pts.length) {
          // throw out oldest point
          for (int j = 1; j < ptNum; j++) {
            pts[j - 1] = pts[j];
          }
          --ptNum;
        } else {
          ptNum++;
        }
      }
      g.drawImage(bimg, 0, 0, this);
    }