Пример #1
0
  /*--------------------------------------------------
   * Paint the text representing the key code
   *-------------------------------------------------*/
  protected void paint(Graphics g) {
    // Clear the background (to white)
    g.setColor(255, 255, 255);
    g.fillRect(0, 0, getWidth(), getHeight());

    // Set color and draw text
    // Draw with black pen
    g.setColor(0, 0, 0);
    // Close to the center
    g.drawImage(image, mX, mY, Graphics.HCENTER | Graphics.VCENTER);
  }
Пример #2
0
  public void paint(Graphics g) {
    g.setColor(255, 255, 255);
    g.fillRect(0, 0, maxX, maxY);

    g.setColor(0, 0, 0);
    // This vertical line start at x/2 position
    g.fillRect((this.maxX / 3) - 1, 0, 3, this.maxY);

    // This vertical line start at 2x/3 position
    g.fillRect(((2 * this.maxX) / 3) - 1, 0, 3, this.maxY);

    // This horizontal line start at this.maxY / 3 - 1 position
    g.fillRect(0, (this.maxY / 3) - 1, this.maxX, 3);

    // This horaizental line start at this.maxY / 3 - 1 position
    g.fillRect(0, ((2 * this.maxY) / 3) - 1, this.maxX, 3);

    // Drawing the selecting rectangle
    g.setColor(255, 0, 0);

    g.drawRect(
        ((this.colSelected * this.maxX) / 3) - 1,
        ((this.rowSelected * this.maxY) / 3) - 1,
        (this.maxX / 3) + 2,
        (this.maxY / 3) + 2);
    g.drawRect(
        (this.colSelected * this.maxX / 3),
        (this.rowSelected * this.maxY / 3),
        this.maxX / 3,
        this.maxY / 3);
    g.drawRect(
        (this.colSelected * this.maxX / 3) + 1,
        (this.rowSelected * this.maxY / 3) + 1,
        (this.maxX / 3) - 2,
        (this.maxY / 3) - 2);

    // Setting X variable for proper placement
    int refX = ((this.maxX / 3) - this.imgWidth) / 2;
    int refY = ((this.maxY / 3) - this.imgHeight) / 2;

    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (this.sq[i][j] == 0) {
          g.setClip(
              (i * this.maxX / 3) + refX,
              (j * this.maxY / 3) + refY,
              this.imgWidth,
              this.imgHeight);
          g.drawImage(
              this.zeroImage,
              ((i * this.maxX / 3) + refX) - this.frame * this.imgWidth,
              (j * this.maxY / 3) + refY,
              Graphics.TOP | Graphics.LEFT);
        } else if (this.sq[i][j] == 1) {
          g.setClip(
              (i * this.maxX / 3) + refX,
              (j * this.maxY / 3) + refY,
              this.imgWidth,
              this.imgHeight);
          g.drawImage(
              this.crossImage,
              ((i * this.maxX / 3) + refX) - this.frame * this.imgWidth,
              (j * this.maxY / 3) + refY,
              Graphics.TOP | Graphics.LEFT);
        }

        g.setClip(0, 0, this.maxX, this.maxY);
      }
    }
  }