예제 #1
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);
      }
예제 #2
0
  public void paint(Graphics g) {
    Rectangle r = g.getClipBounds();

    showStatus("x: " + r.x + " y: " + r.y + " w: " + r.width + " h: " + r.height);

    for (int i = 0; i < numRects; i++) {
      Point lhc = randomPoint(); // left hand corner
      Dimension size = randomDimension();

      g.setColor(colors[(int) (Math.random() * 10)]);

      if (round) {
        if (fill)
          g.fillRoundRect(
              lhc.x,
              lhc.y,
              size.width,
              size.height,
              (int) (Math.random() * 250),
              (int) (Math.random() * 250));
        else
          g.drawRoundRect(
              lhc.x,
              lhc.y,
              size.width,
              size.height,
              (int) (Math.random() * 250),
              (int) (Math.random() * 250));
      } else if (threeD) {
        g.setColor(Color.lightGray);

        if (fill) g.fill3DRect(lhc.x, lhc.y, size.width, size.height, raise);
        else g.draw3DRect(lhc.x, lhc.y, size.width, size.height, raise);
      } else {
        if (fill) g.fillRect(lhc.x, lhc.y, size.width, size.height);
        else g.drawRect(lhc.x, lhc.y, size.width, size.height);
      }
      raise = raise ? false : true;
    }
  }
 // 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);
 }
예제 #4
0
 @Override
 public void paintComponent(Graphics g) {
   if (!antiRepeat && ChessEngine.choice == 0) {
     antiRepeat = true;
     userAsBlack();
   }
   super.paintComponent(g);
   this.setBackground(new Color(200, 100, 0));
   this.addMouseListener(this);
   this.addMouseMotionListener(this);
   // System.out.println("test");
   this.addComponentListener(
       new ComponentAdapter() {
         @Override
         public void componentResized(ComponentEvent e) {
           squareSize = (int) ((Math.min(getHeight(), getWidth()) - 2 * border) / 8);
         }
       });
   for (int i = 0; i < 64; i += 2) { // draw
     g.fillRect(
         (i % 8 + (i / 8) % 2) * squareSize + border,
         (i / 8) * squareSize + border,
         squareSize,
         squareSize);
     g.setColor(new Color(150, 50, 30));
     g.fillRect(
         ((i + 1) % 8 - ((i + 1) / 8) % 2) * squareSize + border,
         ((i + 1) / 8) * squareSize + border,
         squareSize,
         squareSize);
   }
   Image chessPieceImage;
   chessPieceImage = new ImageIcon("ChessPieces.png").getImage();
   for (int i = 0; i < 64; i++) { // draw piece
     int j = -1, k = -1;
     switch (ChessEngine.chessboard[i / 8][i % 8]) {
       case "P":
         j = 5;
         k = 1 - ChessEngine.choice;
         break;
       case "p":
         j = 5;
         k = ChessEngine.choice;
         break;
       case "R":
         j = 2;
         k = 1 - ChessEngine.choice;
         break;
       case "r":
         j = 2;
         k = ChessEngine.choice;
         break;
       case "K":
         j = 4;
         k = 1 - ChessEngine.choice;
         break;
       case "k":
         j = 4;
         k = ChessEngine.choice;
         break;
       case "B":
         j = 3;
         k = 1 - ChessEngine.choice;
         break;
       case "b":
         j = 3;
         k = ChessEngine.choice;
         break;
       case "Q":
         j = 1;
         k = 1 - ChessEngine.choice;
         break;
       case "q":
         j = 1;
         k = ChessEngine.choice;
         break;
       case "A":
         j = 0;
         k = 1 - ChessEngine.choice;
         break;
       case "a":
         j = 0;
         k = ChessEngine.choice;
         break;
     }
     if (j != -1 && k != -1) {
       g.drawImage(
           chessPieceImage,
           (i % 8) * squareSize + border + mouseDrag[i / 8][i % 8][0],
           (i / 8) * squareSize + border + mouseDrag[i / 8][i % 8][1],
           (i % 8 + 1) * squareSize + border + mouseDrag[i / 8][i % 8][0],
           (i / 8 + 1) * squareSize + border + mouseDrag[i / 8][i % 8][1],
           j * 64,
           k * 64,
           (j + 1) * 64,
           (k + 1) * 64,
           this);
     }
     // g.drawString(ChessEngine.chessboard[i/8][i%8], (i%8)*squareSize+border+13,
     // (i/8)*squareSize+border+21);
   }
   g.setColor(Color.BLUE);
   for (int i = 0; i < 8; i++) {
     for (int j = 0; j < 8; j++) {
       if (!chessboard[i][j].equals(ChessEngine.chessboard[i][j])) {
         g.drawRoundRect(
             j * squareSize + border + 3,
             i * squareSize + border + 3,
             squareSize - 6,
             squareSize - 6,
             10,
             10);
         g.drawRoundRect(
             j * squareSize + border + 4,
             i * squareSize + border + 4,
             squareSize - 8,
             squareSize - 8,
             10,
             10);
       }
     }
   }
 }