コード例 #1
0
  /**
   * Draws a new instance of a Rectangle object with the left and right edges of the rectangle at x
   * and x + width. The top and bottom edges are at y and y + height.
   *
   * @pre an intialized DrawingTool
   * @param marco an initialized DrawingTool
   * @post leaves your DrawingTool up and at myX,myY
   */
  public void draw(DrawingTool marco) {

    marco.up();
    marco.move(myX, myY);
    marco.down();
    marco.drawRect(myWidth, myHeight);
    marco.up();
  }
コード例 #2
0
  /**
   * Names your rectangle
   *
   * @param marco an initialized DrawingTool
   * @param name a string with the rectangle's name
   * @post leaves your DrawingTool up and at myX,myY
   */
  public void nameRect(DrawingTool marco, String name) {

    int randomInt = (int) (Math.random() * 6);

    marco.up();
    marco.move(myX - myX, myY);
    marco.down();

    if (randomInt == 0) {
      marco.setColor(Color.yellow);
      marco.drawString(name + ", the Unreadable");

    } else if (randomInt == 1) {
      marco.setColor(Color.pink);
      marco.drawString(name + ", Destroyer of Worlds");

    } else if (randomInt == 2) {
      marco.setColor(Color.red);
      marco.drawString(name + " the Victorious");

    } else if (randomInt == 3) {
      marco.setColor(new Color(128, 0, 128));
      marco.drawString(name + ", of the Pygmy Hippopotami");

    } else if (randomInt == 4) {
      marco.setColor(new Color(255, 235, 205));
      marco.drawString(name + ", of the Blanched Almonds");

    } else if (randomInt == 5) {
      marco.setColor(Color.MAGENTA);
      marco.drawString(name + ", the not-quite-purple");

    } else if (randomInt == 6) {
      marco.drawString(name + " the Boring");
    }
  }