예제 #1
0
파일: TicTac.java 프로젝트: Sykess/Eastwood
  /** PaintComponent to draw everything. */
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    setBackground(Color.WHITE);
    // If using images, use cool dragon background
    if (useImages) g.drawImage(background, 0, 0, 310, 300, null);

    // Use light gray to not overpower the background image
    g.setColor(Color.LIGHT_GRAY);
    for (int y = 1; y < ROWS; ++y)
      g.fillRoundRect(0, cellSize * y - 4, (cellSize * COLS) - 1, 8, 8, 8);
    for (int x = 1; x < COLS; ++x)
      g.fillRoundRect(cellSize * x - 4, 0, 8, (cellSize * ROWS) - 1, 8, 8);

    // Use graphics2d for when not using the images
    Graphics2D g2d = (Graphics2D) g;
    g2d.setStroke(new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    for (int y = 0; y < ROWS; ++y) {
      for (int x = 0; x < COLS; ++x) {
        int x1 = x * cellSize + 16;
        int y1 = y * cellSize + 16;
        if (board[y][x] == Symbol.X) {
          // use image if set to true, otherwise use g2d
          // for thicker, better looking X's and O's
          if (useImages) g.drawImage(imageX, x1, y1, 75, 75, null);
          else {
            g2d.setColor(PURPLE);
            int x2 = (x + 1) * cellSize - 16;
            int y2 = (y + 1) * cellSize - 16;
            g2d.drawLine(x1, y1, x2, y2);
            g2d.drawLine(x2, y1, x1, y2);
          }
        } else if (board[y][x] == Symbol.O) {
          if (useImages) g.drawImage(imageO, x1, y1, 75, 75, null);
          else {
            g2d.setColor(Color.BLUE);
            g2d.drawOval(x1, y1, 70, 70);
          }
        }
      } // end for
    }

    // Set status bar based on gamestate.  If CONTINUE, show whose turn it is
    if (gameStatus == GameStatus.CONTINUE) {
      statusBar.setForeground(Color.BLACK);
      if (currentPlayer == Symbol.X) statusBar.setText("X's Turn");
      else statusBar.setText("O's Turn");
    } else if (gameStatus == GameStatus.DRAW) {
      statusBar.setForeground(Color.RED);
      statusBar.setText("Draw! Click to play again!");
    } else if (gameStatus == GameStatus.X_WIN) {
      statusBar.setForeground(Color.RED);
      statusBar.setText("X has won! Click to play again!");
    } else if (gameStatus == GameStatus.O_WIN) {
      statusBar.setForeground(Color.RED);
      statusBar.setText("O has won! Click to play again!");
    }
  }
예제 #2
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (drawOverlay) {
      g = g.create();
      AntialiasingManager.activateAntialiasing(g);

      try {
        // Paint a roll over fade out.
        FadeTracker fadeTracker = FadeTracker.getInstance();

        float visibility = 0.0f;
        if (fadeTracker.isTracked(this, FadeKind.ROLLOVER)) {
          visibility = fadeTracker.getFade(this, FadeKind.ROLLOVER);
          visibility /= 4;
        } else visibility = 0.5f;

        // Draw black overlay
        g.setColor(new Color(0.0f, 0.0f, 0.0f, visibility));
        g.fillRoundRect(1, 1, width - 2, height - 2, 10, 10);

        // Draw arrow
        g.setColor(Color.WHITE);

        int[] arrowX = new int[] {width - 17, width - 7, width - 12};
        int[] arrowY = new int[] {height - 12, height - 12, height - 7};
        g.fillPolygon(arrowX, arrowY, arrowX.length);
      } finally {
        g.dispose();
      }
    }
  }
예제 #3
0
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   g.setColor(kleur);
   g.fillRoundRect(5, 5, 70, 70, 10, 10);
   g.setColor(Color.black);
   if (waarde == 1) {
     g.fillOval(34, 34, 10, 10);
   } else if (waarde == 2) {
     g.fillOval(10, 10, 10, 10);
     g.fillOval(60, 60, 10, 10);
   } else if (waarde == 3) {
     g.fillOval(10, 10, 10, 10);
     g.fillOval(34, 34, 10, 10);
     g.fillOval(60, 60, 10, 10);
   } else if (waarde == 4) {
     g.fillOval(10, 10, 10, 10);
     g.fillOval(10, 60, 10, 10);
     g.fillOval(60, 10, 10, 10);
     g.fillOval(60, 60, 10, 10);
   } else if (waarde == 5) {
     g.fillOval(10, 10, 10, 10);
     g.fillOval(10, 60, 10, 10);
     g.fillOval(60, 10, 10, 10);
     g.fillOval(60, 60, 10, 10);
     g.fillOval(34, 34, 10, 10);
   } else if (waarde == 6) {
     g.fillOval(10, 10, 10, 10);
     g.fillOval(10, 60, 10, 10);
     g.fillOval(60, 10, 10, 10);
     g.fillOval(60, 60, 10, 10);
     g.fillOval(10, 34, 10, 10);
     g.fillOval(60, 34, 10, 10);
   } else ; // meer waarden zijn er niet
 }
예제 #4
0
 // Draws this die when stopped
 private void drawStopped(Graphics g) {
   int x = xCenter - dieSize / 2;
   int y = yCenter - dieSize / 2;
   g.setColor(Color.RED);
   g.fillRoundRect(x, y, dieSize, dieSize, dieSize / 4, dieSize / 4);
   drawDots(g, x, y, getNumDots());
 }
예제 #5
0
 @Override
 public void paintIcon(Component c, Graphics g, int x, int y) {
   g.setColor(LightColors.SLIGHTLY_GREEN);
   g.fillRoundRect(x + 4, y + 4, 32 - 8, 32 - 8, 8, 8);
   g.setColor(Color.GRAY);
   g.drawRoundRect(x + 4, y + 4, 32 - 8, 32 - 8, 8, 8);
 }
 @Override
 public void paintComponent(Graphics g) {
   if (selected) {
     g.setColor(selColor);
     g.fillRoundRect(0, 0, getWidth(), getHeight(), getWidth() / 10, getHeight() / 10);
     label.setForeground(Color.YELLOW);
   } else label.setForeground(Color.WHITE);
   super.paintComponent(g);
 }
예제 #7
0
  // Draws this die when rolling with a random number of dots
  private void drawRolling(Graphics g) {
    int x = xCenter - dieSize / 2 + (int) (3 * Math.random()) - 1;
    int y = yCenter - dieSize / 2 + (int) (3 * Math.random()) - 1;
    g.setColor(Color.RED);

    if (x % 2 != 0) g.fillRoundRect(x, y, dieSize, dieSize, dieSize / 4, dieSize / 4);
    else g.fillOval(x - 2, y - 2, dieSize + 4, dieSize + 4);

    Die die = new Die();
    die.roll();
    drawDots(g, x, y, die.getNumDots());
  }
예제 #8
0
    /** @{inheritDoc} */
    @Override
    public void paintComponent(Graphics g) {
      super.paintComponent(g);

      g = g.create();

      try {
        AntialiasingManager.activateAntialiasing(g);

        g.setColor(Color.DARK_GRAY);
        g.fillRoundRect(0, 0, this.getWidth(), this.getHeight(), 10, 10);
      } finally {
        g.dispose();
      }
    }
예제 #9
0
  /**
   * ************************************************************************* CONCRETE Class::paint
   * Purpose: The paint() method is an overridden method inherited from JFrame that draws the
   * indicator on the screen. This method must be overridden so that various JRE services can update
   * the display. If you do not override paint, the indicator will not be consistiently drawn to the
   * screen and may have various graphics disappear at run time. This method is invoked indirectly
   * by the repaint() method.
   *
   * <p>Arguments: Graphics g this is the indicator's graphic instance.
   *
   * <p>Returns: none
   *
   * <p>Exceptions: none **************************************************************************
   */
  public void paint(Graphics g) {
    super.paint(g);

    FontMetrics fm = g.getFontMetrics();

    int xLabelPosition = (int) (Height * 0.5) - (int) (fm.stringWidth(MessageLabel) * 0.5);
    int yLabelPosition = (int) (Height * 0.90);
    g.setColor(IluminationColor);
    g.fillRoundRect(
        (int) (Height * 0.15),
        (int) (Height * 0.35),
        (int) (Height * 0.70),
        (int) (Height * 0.40),
        (int) (Height * 0.20),
        (int) (Height * 0.20));
    g.setColor(TextColor);
    g.drawString(MessageLabel, xLabelPosition, yLabelPosition);
  } // paint
예제 #10
0
파일: BoggleGUI.java 프로젝트: nv23/Boggle
      /**
       * Draw one die including the letter centered in the middle of the die. If highlight is true,
       * we reverse the background and letter colors to highlight the die.
       */
      public void paintComponent(Graphics g) {
        super.paintComponent(g);

        int centeredXOffset, centeredYOffset;
        // Draw the blank die
        g.setColor((isHighlighted) ? FACECOLOR : DIECOLOR);
        g.fillRoundRect(0, 0, DIESIZE, DIESIZE, DIESIZE / 2, DIESIZE / 2);

        // Outline the die with black
        g.setColor(Color.black);
        g.drawRoundRect(0, 0, DIESIZE, DIESIZE, DIESIZE / 2, DIESIZE / 2);
        Graphics faceGraphics = faceLabel.getGraphics();
        faceGraphics.setColor(isHighlighted ? DIECOLOR : FACECOLOR);
        Color myColor = isHighlighted ? DIECOLOR : FACECOLOR;
        faceLabel.setForeground(myColor);
        faceLabel.setFont(FACEFONT);
        faceLabel.setText(face);
      }
예제 #11
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    g.setColor(Color.GRAY);
    g.drawLine(200, 15, 200, 170);

    g.setColor(Color.BLACK);
    g.setFont(new Font("SansSerif", Font.BOLD, 14));
    g.drawString("TWOJA RĘKA", 55, 30);
    g.drawString("WSPÓLNE", 405, 30);

    for (int i = 0; i < 7; i++) {
      if (game.cards[i] != null) {
        g.setColor(Color.WHITE);
        g.fillRoundRect(10 + 100 * i, 40, 80, 120, 20, 20);
        int suite = game.cards[i].getSuite();
        if (suite == 0) {
          g.drawImage(spade, 27 + 100 * i, 50, null);
        } else if (suite == 1) {
          g.drawImage(heart, 27 + 100 * i, 50, null);
        } else if (suite == 2) {
          g.drawImage(diamond, 27 + 100 * i, 50, null);
        } else if (suite == 3) {
          g.drawImage(club, 27 + 100 * i, 50, null);
        }

        g.setColor(Color.BLACK);
        g.setFont(new Font("Serif", Font.PLAIN, 28));

        int offset = 41;

        if (game.cards[i].getStrenght() == 8) {
          offset = 37;
        }

        g.drawString(strenght2String(game.cards[i].getStrenght()), offset + 100 * i, 135);
      }
    }
  }
예제 #12
0
 @Override
 public void paint(Graphics g, JComponent c) {
   final Border border = c.getBorder();
   final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
   final boolean square = isSquare(c);
   if (c.isEnabled() && border != null) {
     final Insets ins = border.getBorderInsets(c);
     final int yOff = (ins.top + ins.bottom) / 4;
     if (!square) {
       if (((JButton) c).isDefaultButton()) {
         ((Graphics2D) g)
             .setPaint(
                 UIUtil.getGradientPaint(
                     0,
                     0,
                     getSelectedButtonColor1(),
                     0,
                     c.getHeight(),
                     getSelectedButtonColor2()));
       } else {
         ((Graphics2D) g)
             .setPaint(
                 UIUtil.getGradientPaint(
                     0, 0, getButtonColor1(), 0, c.getHeight(), getButtonColor2()));
       }
     }
     g.fillRoundRect(
         square ? 2 : 4,
         yOff,
         c.getWidth() - 2 * 4,
         c.getHeight() - 2 * yOff,
         square ? 3 : 5,
         square ? 3 : 5);
   }
   config.restore();
   super.paint(g, c);
 }
예제 #13
0
 @Override
 public void paintIcon(Component c, Graphics g, int x, int y) {
   g.setColor(color);
   g.fillRoundRect(x + 1, y + 1, 22, 22, 10, 10);
 }
 // This class represents rectangle shapes with rounded corners.
 // (Note that it uses the inherited version of the
 // containsPoint(x,y) method, even though that is not perfectly
 // accurate when (x,y) is near one of the corners.)
 void draw(Graphics g) {
   g.setColor(color);
   g.fillRoundRect(left, top, width, height, width / 3, height / 3);
   g.setColor(Color.black);
   g.drawRoundRect(left, top, width, height, width / 3, height / 3);
 }