Ejemplo n.º 1
0
  // draw rectangles and arcs
  public void paintComponent(Graphics g) {
    super.paintComponent(g); // call superclass's paintComponent

    // start at 0 and sweep 360 degrees
    g.setColor(Color.RED);
    g.drawRect(15, 35, 80, 80);
    g.setColor(Color.BLACK);
    g.drawArc(15, 35, 80, 80, 0, 360);

    // start at 0 and sweep 110 degrees
    g.setColor(Color.RED);
    g.drawRect(100, 35, 80, 80);
    g.setColor(Color.BLACK);
    g.drawArc(100, 35, 80, 80, 0, 110);

    // start at 0 and sweep -270 degrees
    g.setColor(Color.RED);
    g.drawRect(185, 35, 80, 80);
    g.setColor(Color.BLACK);
    g.drawArc(185, 35, 80, 80, 0, -270);

    // start at 0 and sweep 360 degrees
    g.fillArc(15, 120, 80, 40, 0, 360);

    // start at 270 and sweep -90 degrees
    g.fillArc(100, 120, 80, 40, 270, -90);

    // start at 0 and sweep -270 degrees
    g.fillArc(185, 120, 80, 40, 0, -270);
  } // end method paintComponent
Ejemplo n.º 2
0
  /** Overrides <code>Graphics.fillArc</code>. */
  public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
    DebugGraphicsInfo info = info();

    if (debugLog()) {
      info()
          .log(
              toShortString()
                  + " Filling arc: "
                  + new Rectangle(x, y, width, height)
                  + " startAngle: "
                  + startAngle
                  + " arcAngle: "
                  + arcAngle);
    }
    if (isDrawingBuffer()) {
      if (debugBuffered()) {
        Graphics debugGraphics = debugGraphics();

        debugGraphics.fillArc(x, y, width, height, startAngle, arcAngle);
        debugGraphics.dispose();
      }
    } else if (debugFlash()) {
      Color oldColor = getColor();
      int i, count = (info.flashCount * 2) - 1;

      for (i = 0; i < count; i++) {
        graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
        graphics.fillArc(x, y, width, height, startAngle, arcAngle);
        Toolkit.getDefaultToolkit().sync();
        sleep(info.flashTime);
      }
      graphics.setColor(oldColor);
    }
    graphics.fillArc(x, y, width, height, startAngle, arcAngle);
  }
Ejemplo n.º 3
0
  /** paints the Spinner */
  public void paint(Graphics g) {
    int start_angle = 90;
    int done_angle = (int) (percentDone * 360);

    g.setColor(getBackground());
    g.fillArc(3, 3, getSize().width - 8, getSize().height - 8, 0, 360);

    g.setColor(getForeground());
    g.fillArc(3, 3, getSize().width - 8, getSize().height - 8, start_angle, done_angle);

    g.setColor(Color.black);
    g.drawArc(3, 3, getSize().width - 8, getSize().height - 8, 0, 360);
  }
Ejemplo n.º 4
0
  @Override
  protected void paintComponent(Graphics g) {
    // TODO Auto-generated method stub
    super.paintComponent(g);
    // g.drawLine(0, 300, 600, 50);
    g.setColor(Color.YELLOW);
    g.fillOval(x, 50, 500, 500);
    g.setColor(Color.WHITE);
    g.fillOval(150, 100, 100, 100);
    g.fillOval(350, 100, 100, 100);
    g.setColor(Color.BLUE);
    // g.fillOval(180, y, 50, 50);
    // g.fillOval(380, 100, 50, 50);
    g.setColor(Color.RED);
    g.fillArc(x3, 350, 350, 150, 180, 180);
    g.setColor(Color.MAGENTA);
    g.fillArc(x2, 350, 100, 200, 200, -200);
    g.setColor(Color.BLACK);

    g.setColor(Color.BLUE);
    g.fillOval(180, y, 50, h);
    g.fillOval(380, y, 50, h);
    y++;
    if (y == 150) {
      y = 100;
    }
    x--;
    if (x == 50) {
      x = 100;
    }
    x2--;
    if (x2 == 200) {
      x2 = 250;
    }
    h++;
    if (h == 50) {
      h = 0;
    }
    x3--;
    if (x3 == 100) {
      x3 = 150;
    }

    try {
      Thread.sleep(20);
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    super.repaint();
  }
Ejemplo n.º 5
0
  // Draw four blazes of a fan
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    int xCenter = getSize().width / 2;
    int yCenter = getSize().height / 2;
    int radius = (int) (Math.min(getSize().width, getSize().height) * 0.4);

    int x = xCenter - radius;
    int y = yCenter - radius;

    g.fillArc(x, y, 2 * radius, 2 * radius, 0, 30);
    g.fillArc(x, y, 2 * radius, 2 * radius, 90, 30);
    g.fillArc(x, y, 2 * radius, 2 * radius, 180, 30);
    g.fillArc(x, y, 2 * radius, 2 * radius, 270, 30);
  }
Ejemplo n.º 6
0
  public void paint(Graphics g) {

    g.setColor(Color.green);

    g.drawRect(25, 50, 200, 0);

    g.drawRect(25, 100, 200, 100);

    g.drawRoundRect(25, 250, 200, 100, 10, 10);

    g.drawRect(250, 100, 250, 100);
    g.fillRect(250, 100, 250, 100);

    g.setColor(Color.black);
    g.drawOval(250, 100, 250, 100);

    g.setColor(Color.green);
    g.drawOval(250, 250, 250, 99);
    g.fillOval(250, 250, 250, 100);

    g.drawOval(550, 100, 250, 100);
    g.drawArc(550, 100, 250, 100, 90, 82);
    g.fillArc(550, 100, 250, 100, 90, 82);

    g.drawOval(600, 250, 100, 100);
  }
Ejemplo n.º 7
0
  private void draw_horizon(int rad, Point center, int[] angles) {
    // Draw an arc
    int arc_angle =
        ((angles[0] > angles[1]) ? (360 - angles[0]) + angles[1] : (angles[1] - angles[0]));

    Polygon remainder = new Polygon();

    offgraphics_.setColor(GREEN);
    offgraphics_.fillArc(center.x - rad, center.y - rad, 2 * rad, 2 * rad, angles[0], arc_angle);

    if (pitch_ != 0) {
      if ((pitch_ > 0 && Math.abs(roll_) < 90) || (pitch_ < 0 && Math.abs(roll_) >= 90))
        offgraphics_.setColor(BLUE);

      int cover_angle = (angles[0] + arc_angle / 2 + ((arc_angle < 180) ? 180 : 0)) % 360;

      // System.out.println (points[0] + " " + points[1]);

      // System.out.println (accepted_point);

      remainder.addPoint(
          center.x + polar_to_rect_x(rad, cover_angle),
          center.y - polar_to_rect_y(rad, cover_angle));
      remainder.addPoint(
          center.x + polar_to_rect_x(rad, angles[0]), center.y - polar_to_rect_y(rad, angles[0]));
      remainder.addPoint(
          center.x + polar_to_rect_x(rad, angles[1]), center.y - polar_to_rect_y(rad, angles[1]));
      offgraphics_.fillPolygon(remainder);
      // offgraphics_.setColor (getBackground ());
      // offgraphics_.drawPolygon (remainder);
    }
  }
Ejemplo n.º 8
0
  /**
   * If categories, summaries, or colors is empty, throws an IllegalArgumentException.
   *
   * <p>If categories, summaries, and colors don't have the same number of elements, throws an
   * IllegalArgumentException.
   *
   * <p>If any of the numbers in summaries is non-positive, throws an IllegalArgumentException.
   *
   * <p>Otherwise, views the three lists as a table with a String, a double, and a Color in each
   * column and displays the data with either a pie chart (if usePieChart is true) or a bar graph
   * (otherwise). Let SUM be the sum of all the entries in summaries. The area of slice i (of a pie
   * chart) and the length of bar i (in a bar graph) should be proportional to categories[i]/SUM.
   * The slice/bar should be labeled with categories[i] and summaries[i], and it should be colored
   * with colors[i].
   *
   * <p>For example, suppose we are given this data:
   *
   * <pre>
   *  Utah       14    Color.RED
   *  Nevada     14    Color.BLUE
   *  California 28    Color.GREEN
   * </pre>
   *
   * In a pie chart Utah and Nevada should each have a quarter of the pie and California should have
   * half. In a bar graph, California's line should be twice as long as Utah's and Nevada's.
   *
   * <p>The method should display the pie chart or bar graph by drawing on the g parameter. The
   * example code below draws both a pie chart and a bar graph for the situation described above.
   */
  public static void drawGraph(
      Graphics g,
      ArrayList<String> categories,
      ArrayList<Double> summaries,
      ArrayList<Color> colors,
      boolean usePieChart) {
    if (categories.size() == 0 || summaries.size() == 0 || colors.size() == 0) {
      throw new IllegalArgumentException(
          "Categories, summaries, and colors cannot be empty lists.");
    }
    if (categories.size() != summaries.size() || colors.size() != categories.size()) {
      throw new IllegalArgumentException(
          "Categories, summaries, and colors must be the same length.");
    }
    // find proportions of each slice/bar
    ArrayList<Double> proportions = graphProportions(summaries);

    if (usePieChart) {
      // find portions in degrees
      ArrayList<Double> degrees = findPieDegrees(proportions);

      // plug in values using for loop
      int labelYPosition = 5;
      int rectangleYPosition = -5;
      double startingDegree = 0;
      double revolveDegree = 360;

      int i = 0;
      for (i = 0; i < categories.size(); i++) {
        labelYPosition += 15;
        rectangleYPosition += 15;

        g.setColor(colors.get(i));
        g.fillArc(10, 10, DIAMETER, DIAMETER, (int) startingDegree, (int) revolveDegree);
        g.fillRect(DIAMETER + SPACING, rectangleYPosition, 10, 10);
        g.setColor(Color.black);
        g.drawString(categories.get(i) + " " + summaries.get(i), 350, labelYPosition);

        startingDegree += degrees.get(i);
        revolveDegree -= degrees.get(i);
      }

    } else {

      int i = 0;
      int yBarPos = 10;
      int yLabelPos = 25;
      for (i = 0; i < categories.size(); i++) {
        double start = FULLBAR - FULLBAR * proportions.get(i);
        double prop = FULLBAR * proportions.get(i);

        g.setColor(colors.get(i));
        g.fillRect((int) start + 10, yBarPos, (int) prop, 20);
        g.setColor(Color.black);
        g.drawString(categories.get(i) + " " + summaries.get(i), 330, yLabelPos);
        yBarPos += 30;
        yLabelPos += 30;
      }
    }
  }
Ejemplo n.º 9
0
  public void paint(Graphics page) {

    {
      Font f = new Font("SAO UI", Font.BOLD, 36);
      Font g = new Font("SAO UI", Font.BOLD, 24);
      page.setFont(g);
      int wd, ht;
      int x, y;

      x = 50;
      y = 150;
      wd = 250;
      ht = 250;

      page.setColor(new Color(216, 0, 0));
      page.fillArc(x, y, wd, ht, 90, -126);
      page.drawString("RENT AND UTILITIES - 35%", 290, 200);
      page.setColor(new Color(0, 216, 0));
      page.fillArc(x, y, wd, ht, 270, 54);
      page.drawString("TRANSPORTATION - 15%", 250, 400);
      page.setColor(new Color(0, 0, 216));
      page.fillArc(x, y, wd, ht, 216, 54);
      page.drawString("FOOD - 15%", 10, 400);
      page.setColor(new Color(216, 216, 0));
      page.fillArc(x, y, wd, ht, 126, 90);
      page.drawString("EDU. - 25%", 5, 180);
      page.setColor(new Color(0, 216, 216));
      page.fillArc(x, y, wd, ht, 90, 36);
      page.drawString("MISC. - 10%", 50, 150);

      // (250, 200) is the top left of a box around the oval

      // 50 and 50 is the width and height of the box around the oval

      // 90 is the startAngle.  0 is far right, 90 is the top of the oval

      // 180 is the arcLength.  180 means starting at 90 and ending at 270 degrees

      page.setColor(Color.black);
      page.setFont(f);
      page.drawString("HOUSEHOLD SPENDING ON VARIOUS EXPENSES", 20, 30);
    }
  }
Ejemplo n.º 10
0
 public void paint(Graphics g) {
   g.drawString("Hello", 40, 40);
   setBackground(Color.white);
   g.fillRect(130, 30, 100, 80);
   g.drawOval(30, 130, 50, 60);
   setForeground(Color.red);
   g.fillOval(130, 130, 50, 60);
   g.drawArc(30, 200, 40, 50, 90, 60);
   g.fillArc(50, 200, 40, 20, 180, 40);
 }
Ejemplo n.º 11
0
    public void drawSegment(Point p1, Point p2, Color color) {
      g.setColor(color);

      double t = Math.atan2(p2.x - p1.x, p2.y - p1.y);
      double cosT = Math.cos(t);
      double sinT = Math.sin(t);
      int deg = (int) Math.toDegrees(t);
      if (selected) {
        int[] x =
            new int[] {
              (int) (p1.x + 5 * cosT),
              (int) (p2.x + 5 * cosT),
              (int) (p2.x - 5 * cosT),
              (int) (p1.x - 5 * cosT)
            };
        int[] y =
            new int[] {
              (int) (p1.y - 5 * sinT),
              (int) (p2.y - 5 * sinT),
              (int) (p2.y + 5 * sinT),
              (int) (p1.y + 5 * sinT)
            };
        g.fillPolygon(x, y, 4);
        g.fillArc(p1.x - 5, p1.y - 5, 10, 10, deg, 180);
        g.fillArc(p2.x - 5, p2.y - 5, 10, 10, deg, -180);
      } else {
        g.drawLine(
            (int) (p1.x + 5 * cosT),
            (int) (p1.y - 5 * sinT),
            (int) (p2.x + 5 * cosT),
            (int) (p2.y - 5 * sinT));
        g.drawLine(
            (int) (p1.x - 5 * cosT),
            (int) (p1.y + 5 * sinT),
            (int) (p2.x - 5 * cosT),
            (int) (p2.y + 5 * sinT));
        g.drawArc(p1.x - 5, p1.y - 5, 10, 10, deg, 180);
        g.drawArc(p2.x - 5, p2.y - 5, 10, 10, deg, -180);
      }
    }
Ejemplo n.º 12
0
  public void paintStadium(Graphics g) {
    g.setColor(new Color(100, 255, 100));
    g.fillRect(0, 0, 720, 430);

    g.setColor(new Color(200, 255, 200));
    g.fillOval(310, 165, 100, 100);
    g.fillArc(70, 165, 100, 100, -90, 180);
    g.fillArc(550, 165, 100, 100, 90, 180);
    g.fillOval(-18, -18, 36, 36);
    g.fillOval(-18, 412, 36, 36);
    g.fillOval(702, 412, 36, 36);
    g.fillOval(702, -18, 36, 36);
    g.fillRect(0, 110, 120, 210);
    g.fillRect(600, 110, 120, 210);

    g.setColor(new Color(100, 255, 100));
    g.fillOval(314, 169, 92, 92);
    g.fillArc(74, 169, 92, 92, -90, 180);
    g.fillArc(554, 169, 92, 92, 90, 180);
    g.fillOval(-14, -14, 28, 28);
    g.fillOval(-14, 416, 28, 28);
    g.fillOval(706, 416, 28, 28);
    g.fillOval(706, -14, 28, 28);
    g.fillRect(0, 114, 116, 202);
    g.fillRect(604, 114, 116, 202);

    g.setColor(new Color(200, 255, 200));
    g.fillRect(358, 0, 4, 430);
    g.fillRect(0, 165, 60, 4);
    g.fillRect(660, 165, 60, 4);
    g.fillRect(0, 261, 60, 4);
    g.fillRect(660, 261, 60, 4);
    g.fillRect(60, 165, 4, 100);
    g.fillRect(660, 165, 4, 100);

    g.setColor(new Color(0, 0, 0));
    g.fillRect(0, 175, 4, 80);
    g.fillRect(716, 175, 4, 80);
  }
  @Override
  public void paint(Graphics g) {
    System.out.println("Thread invoked the paint() " + Thread.currentThread().getName());
    g.setColor(Color.BLACK);
    g.setFont(textFont);
    g.drawString(timeMessage, 0, 15);
    g.fillOval(0, 20, 100, 100);

    g.setColor(Color.WHITE);
    g.fillOval(3, 23, 94, 94);

    g.setColor(Color.BLUE);
    g.fillArc(2, 22, 96, 96, 90, -arcLen);
  }
Ejemplo n.º 14
0
  /**
   * Draws a "solid" arc which will look either like a pie wedge or Pac-man.<br>
   * A FILLED ARC is a "piece" of a SOLID OVAL.<br>
   * The first 5 parameters (g and 4 ints) are the same as drawOval.<br>
   * There are 2 additional parameters for the starting degree value and finishing degree of the
   * arc. <br>
   * 0 degrees is at the 12:00 position and the degrees progress in a CLOCKWISE fashion. <br>
   * (90 degrees is at 3:00, 180 degrees is at 6:00, 270 degrees is at 9:00, 360 degrees is back at
   * 12:00).
   */
  public static void fillArc(
      Graphics g, int centerX, int centerY, int hRadius, int vRadius, int start, int finish) {
    int hDiameter = 2 * hRadius;
    int vDiameter = 2 * vRadius;

    if (finish < start) finish += 360;
    int newStart = 90 - start; // shifts starting position from 3:00 to 12:00
    int newFinish =
        start
            - finish; // as oppose to finish-start.  Subtracting backwards changes from
                      // counter-clockwise to clockwise.

    g.fillArc(centerX - hRadius, centerY - vRadius, hDiameter, vDiameter, newStart, newFinish);
  }
  /* public void draw_visualization_2(Graphics g) {
          g.setColor(new Color(230, 140, 170));
          if (flag_2 == true) {

              g.setColor(new Color(250, 20, 5));
          } else {

              g.setColor(new Color(5, 250, 20));
          }
          g.drawArc(120, 140, 40, 40, 0, 360);
          g.drawLine(140, 180, 140, 230);
          g.drawLine(140, 230, 100, 260);
          g.drawLine(140, 230, 180, 260);
          g.drawLine(140, 180, 100, 200);
          g.drawLine(140, 180, 180, 200);



      }
  */
  public void draw_a(Graphics g) {
    int p = -35, r = -50;

    g.translate(p, r);
    p = p + 10;
    r = r + 12;
    g.setColor(new Color(250, 0, 0));
    g.drawPolyline(a_x, a_y, 6);
    g.setColor(new Color(0, 250, 0));
    g.drawPolyline(a_x_1, a_y_1, 6);
    g.setColor(new Color(0, 0, 250));
    g.drawPolyline(a_x_2, a_y_2, 6);
    g.setColor(new Color(74, 124, 197));
    g.drawPolyline(a_x_3, a_y_3, 6);
    g.translate(p, r);
    p = p + 10;
    r = r + 12;

    g.setColor(new Color(250, 0, 0));
    g.drawArc(a_x[5] - 20, a_y[5] - 20, 20, 20, 0, 360);
    g.fillArc(a_x[5] - 20, a_y[5] - 20, 20, 20, 0, 360);
    g.setColor(new Color(0, 250, 0));
    g.drawArc(a_x_1[5] - 20, a_y_1[5] - 20, 20, 20, 0, 360);
    g.fillArc(a_x_1[5] - 20, a_y_1[5] - 20, 20, 20, 0, 360);
    g.setColor(new Color(0, 0, 250));
    g.drawArc(a_x_2[5] - 20, a_y_2[5] - 20, 20, 20, 0, 360);
    g.fillArc(a_x_2[5] - 20, a_y_2[5] - 20, 20, 20, 0, 360);
    g.setColor(new Color(74, 124, 197));
    g.drawArc(a_x_3[5] - 20, a_y_3[5] - 20, 20, 20, 0, 360);
    g.fillArc(a_x_3[5] - 20, a_y_3[5] - 20, 20, 20, 0, 360);

    g.translate(p, r);
    p = p + 10;
    r = r + 12;
    // drawetc(g);

  }
Ejemplo n.º 16
0
  void drawMazeMan(boolean open) {
    Graphics g = parent.getGraphics();
    g.setColor(Color.yellow);

    if (open) g.fillArc(x, y, width, height, startangle, 270);
    else {
      g.fillOval(x, y, width, height);
      g.setColor(Color.black);
      switch (direction) {
        case 1:
          g.drawLine(x + 9, y + 9, x + 18, y + 9);
          break;
        case 2:
          g.drawLine(x + 9, y + 9, x + 9, y + 18);
          break;
        case 3:
          g.drawLine(x + 9, y + 9, x, y + 9);
          break;
        case 4:
          g.drawLine(x + 9, y + 9, x + 9, y);
          break;
      }
    }
    g.setColor(Color.black);
    g.fillOval(x + eyeX, y + eyeY, 3, 3);

    if ((parent.focussed) & (!parent.reportscore)) {
      g.setColor(new Color(0, 0, 0)); // change the bg color
      g.fillRect(0, 330, 400, 350);
      g.setColor(Color.yellow);
      parent.totaltime = (int) ((System.currentTimeMillis() - parent.starttime) / 1000);
      g.drawString("" + parent.totaltime + " seconds", 10, 360);
    }

    parent.done = true;
    for (parent.b = 0; parent.b < 20; parent.b++) {
      for (parent.a = 0; parent.a < 16; parent.a++) {
        if ((parent.matrix[parent.a][parent.b] == 2) | (parent.matrix[parent.a][parent.b] == 3))
          parent.done = false;
      }
    }
    if ((parent.done) & (!parent.reportscore)) {
      g.setColor(Color.yellow);

      // g.drawString("You complete the maze in " + parent.totaltime + " seconds.",10,380);
      parent.reportscore = true;
      InsertData s = new InsertData(g, parent.totaltime);
    }
  }
Ejemplo n.º 17
0
  public void paint(Graphics g) {
    g.setFont(bigFont);
    g.drawString("Shapes and Colors", 80, 20);

    g.setColor(redColor);

    g.drawRect(100, 100, 100, 100);

    g.fillRect(110, 110, 80, 80);
    g.setColor(weirdColor);
    g.fillArc(120, 120, 60, 60, 0, 360);
    g.setColor(Color.yellow);
    g.drawLine(140, 140, 160, 160);
    g.setColor(Color.black);
  }
Ejemplo n.º 18
0
 @Override
 public void paintComponent(Graphics g) {
   if (slices != null && !slices.isEmpty()) {
     Arc2D arc2D = null;
     double start = 0;
     int size = Math.min(getWidth(), getHeight()) - 10;
     int x = getWidth() / 2 - size / 2;
     int y = getHeight() / 2 - size / 2;
     if (g instanceof Graphics2D) {
       arc2D = new Arc2D.Double(Arc2D.PIE);
       arc2D.setFrame(x, y, size, size);
       ((Graphics2D) g)
           .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
     }
     for (PieSlice slice : slices) {
       double arc = (slice.cost / total) * 360.0;
       if (g instanceof Graphics2D) {
         arc2D.setAngleStart(start);
         arc2D.setAngleExtent(arc);
         Color c = ScenarioColorPalette.getColor(slice.toString());
         g.setColor(slice.equals(highlighted) ? c.brighter() : c);
         ((Graphics2D) g).fill(arc2D);
         g.setColor(Color.BLACK);
         ((Graphics2D) g).draw(arc2D);
       } else {
         g.setColor(ScenarioColorPalette.getColor(slice.toString()));
         g.fillArc(x, y, size, size, (int) start, (int) arc);
         g.setColor(Color.BLACK);
         g.drawArc(x, y, size, size, (int) start, (int) arc);
       }
       start += arc;
     }
     g.setColor(ScenarioColorPalette.getColor("Untagged"));
     g.fillArc(x, y, size, size, (int) start, (int) (360.0 - start));
   }
 }
Ejemplo n.º 19
0
  public void paintComponent(Graphics g) {
    String str = "by Roman Nemchinov";
    g.fillRect(0, 0, this.getWidth(), this.getHeight());

    int red = (int) (Math.random() * 255);
    int green = (int) (Math.random() * 255);
    int blue = (int) (Math.random() * 255);

    Color randomColor = new Color(red, green, blue);
    g.setColor(randomColor);
    g.fillRect(30, 30, 70, 70);
    g.fillOval(140, 25, 80, 80);
    g.drawString(str, 80, 230);
    g.fillRoundRect(30, 110, 70, 70, 30, 30);
    g.fillArc(140, 110, 70, 70, 250, 250);
  }
Ejemplo n.º 20
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    int centerX = this.getWidth() / 2;
    int centerY = this.getHeight() / 2;
    int radius = Math.min(getWidth() - 4, getHeight() - 4) / 2;
    double angle = myController.getValue() * 2 * Math.PI;

    g.fillOval(centerX - radius, centerY - radius, radius * 2, radius * 2);
    g.setColor(Color.yellow);
    g.fillArc(
        centerX - radius, centerY - radius, radius * 2, radius * 2, 0, (int) Math.toDegrees(angle));

    int pinX = centerX + (int) (Math.cos(angle) * radius);
    int pinY = centerY - (int) (Math.sin(angle) * radius);
    g.setColor(Color.gray.brighter());
    g.fill3DRect(pinX - 4, pinY - 4, 8, 8, true);
  }
Ejemplo n.º 21
0
  private void drawCluster(Graphics g, List<ClusterVM> cvms) {
    Color cache = g.getColor();

    for (int i = 0; i < cvms.size(); i++) {
      ClusterVM cvm = cvms.get(i);
      Observation loc = cvm.getCluster().getCentroid();
      int cx = (int) loc.x, cy = (int) loc.y;
      int r = clusterRadius;
      Color color = cvm.getClusterColor();
      g.setColor(color);
      g.fillArc(cx - r, cy - r, 1 + 2 * r, 1 + 2 * r, 0, 360);
      g.setColor(Color.WHITE);
      g.drawArc(cx - r, cy - r, 1 + 2 * r, 1 + 2 * r, 0, 360);
      g.setColor(Color.BLACK);
      g.drawArc(cx - r - 1, cy - r - 1, 1 + 2 * r + 2, 1 + 2 * r + 2, 0, 360);
    }

    g.setColor(cache);
  }
Ejemplo n.º 22
0
 private static void paintArc(Graphics g, RemoteArc arc, boolean fill) {
   try {
     Rectangle bounds = arc.getBounds();
     if (fill)
       g.fillArc(
           bounds.x,
           bounds.y,
           bounds.width,
           bounds.height,
           arc.getStartAngle(),
           arc.getEndAngle());
     else
       g.drawArc(
           bounds.x,
           bounds.y,
           bounds.width,
           bounds.height,
           arc.getStartAngle(),
           arc.getEndAngle());
   } catch (Exception e) {
     e.printStackTrace();
     // System.out.println(e);
   }
 }
 // Draws a sector, centered at x, y, of radius r,
 // of angle measure degrees, starting at fromDegree.
 private void drawSector(Graphics g, int x, int y, int r, int fromDegree, int degrees) {
   if (degrees > 359) g.fillOval(x - r, y - r, 2 * r, 2 * r);
   else g.fillArc(x - r, y - r, 2 * r, 2 * r, fromDegree, degrees);
 }
Ejemplo n.º 24
0
  // drawing of the game happens in here
  // we use the Graphics object, g, to perform the drawing
  // NOTE: This is already double buffered!(helps with framerate/speed)
  @Override
  public void paintComponent(Graphics g) {
    // always clear the screen first!
    g.clearRect(0, 0, WIDTH, HEIGHT);

    // GAME DRAWING GOES HERE
    // Background
    g.setColor(Color.CYAN);
    g.fillRect(0, 0, WIDTH, HEIGHT);

    // Hair
    // Color hair = new Color(94, 52, 25);
    g.setColor(Color.RED);
    g.fillOval(175, 200, 150, 150);
    g.fillOval(150, 250, 150, 150);
    g.fillOval(375, 200, 150, 150);
    g.fillOval(400, 250, 150, 150);
    g.fillOval(200, 150, 300, 300);
    g.fillOval(425, 300, 150, 150);
    g.fillOval(125, 300, 150, 150);
    g.fillOval(450, 350, 150, 150);
    g.fillOval(100, 350, 150, 150);
    g.fillOval(200, 300, 300, 300);
    g.fillOval(475, 400, 150, 150);
    g.fillOval(75, 400, 150, 150);
    g.fillOval(500, 450, 150, 150);
    g.fillOval(50, 450, 150, 150);
    g.fillOval(400, 450, 150, 150);
    g.fillOval(150, 450, 150, 150);

    // Head
    Color skin = new Color(255, 226, 201);
    g.setColor(skin);
    g.fillOval(200, 200, 300, 300);

    // Eyebrows
    g.setColor(Color.RED);
    g.fillOval(273, 280, 50, 50);
    g.fillOval(380, 280, 50, 50);

    g.setColor(skin);
    g.fillOval(273, 285, 50, 50);
    g.fillRect(273, 295, 50, 50);
    g.fillOval(380, 285, 50, 50);
    g.fillRect(380, 295, 50, 50);

    // Hair
    g.setColor(Color.RED);
    g.fillArc(200, 130, 150, 150, 200, 180);
    g.fillArc(350, 130, 150, 150, 150, 180);
    g.fillArc(170, 210, 100, 100, 200, 180);
    g.fillArc(435, 210, 100, 100, 150, 180);

    // Eyes
    g.setColor(Color.WHITE);
    g.fillOval(275, 295, 45, 45);
    g.fillOval(380, 295, 45, 45);
    g.setColor(Color.BLUE);
    g.fillOval(280, 300, 35, 35);
    g.fillOval(385, 300, 35, 35);
    g.setColor(Color.BLACK);
    g.fillOval(leftEye.x, leftEye.y, leftEye.width, leftEye.height);
    g.fillOval(rightEye.x, rightEye.y, rightEye.width, rightEye.height);

    // Nose
    Color shade = new Color(240, 205, 175);
    g.setColor(shade);
    g.fillRect(340, 350, 20, 20);

    // Mouth
    Color mouth = new Color(255, 92, 89);
    g.setColor(mouth);
    g.fillArc(310, 360, 75, 75, 180, 180);

    // GAME DRAWING ENDS HERE
  }
Ejemplo n.º 25
0
    @Override
    protected void paintComponent(Graphics g) {
      super.paintComponent(g);

      // Get the appropriate size for the figure
      int width = getWidth();
      int height = getHeight();

      switch (type) {
        case LINE: // Display two cross lines
          g.setColor(Color.BLACK);
          g.drawLine(10, 10, width - 10, height - 10);
          g.drawLine(width - 10, 10, 10, height - 10);
          break;
        case RECTANGLE: // Display a rectangle
          g.setColor(Color.blue);
          if (filled)
            g.fillRect(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height));
          else
            g.drawRect(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height));
          break;
        case ROUND_RECTANGLE: // Display a round-cornered rectangle
          g.setColor(Color.red);
          if (filled)
            g.fillRoundRect(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                20,
                20);
          else
            g.drawRoundRect(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                20,
                20);
          break;
        case OVAL: // Display an Oval
          g.setColor(Color.black);
          if (filled)
            g.fillOval(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height));
          else
            g.drawOval(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height));
          break;
        case ARC: // Display an arc
          g.setColor(Color.blue);
          if (filled) {
            g.fillArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                0,
                30);
            g.fillArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                90,
                30);
            g.fillArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                180,
                30);
            g.fillArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                270,
                30);
          } else {
            g.drawArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                0,
                30);
            g.drawArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                90,
                30);
            g.drawArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                180,
                30);
            g.drawArc(
                (int) (0.1 * width),
                (int) (0.1 * height),
                (int) (0.8 * width),
                (int) (0.8 * height),
                270,
                30);
          }
          break;

        case POLYGON:
          g.setColor(Color.red);
          int radius = (int) (0.4 * Math.min(width, height));
          int xCenter = (int) (0.4 * width);
          int yCenter = (int) (0.4 * height);
          Polygon p = new Polygon();
          p.addPoint(xCenter + radius, yCenter);

          p.addPoint(
              (int) (xCenter + radius * Math.cos(2 * Math.PI / 6)),
              (int) (yCenter - radius * Math.sin(2 * Math.PI / 6)));

          p.addPoint(
              (int) (xCenter + radius * Math.cos(2 * 2 * Math.PI / 6)),
              (int) (yCenter - radius * Math.sin(2 * 2 * Math.PI / 6)));

          p.addPoint(
              (int) (xCenter + radius * Math.cos(3 * 2 * Math.PI / 6)),
              (int) (yCenter - radius * Math.sin(3 * 2 * Math.PI / 6)));

          p.addPoint(
              (int) (xCenter + radius * Math.cos(4 * 2 * Math.PI / 6)),
              (int) (yCenter - radius * Math.sin(4 * 2 * Math.PI / 6)));

          p.addPoint(
              (int) (xCenter + radius * Math.cos(5 * 2 * Math.PI / 6)),
              (int) (yCenter - radius * Math.sin(5 * 2 * Math.PI / 6)));

          if (filled) {
            g.fillPolygon(p);
          } else {
            g.drawPolygon(p);
          }
          break;

        default:
          g.setColor(Color.BLACK);
          g.drawLine(10, 10, width - 10, height - 10);
          g.drawLine(width - 10, 10, 10, height - 10);
          break;
      }
    }
Ejemplo n.º 26
0
  // Private support methods
  private void drawAnalogClock(Graphics g) {
    Dimension d = getSize();
    int centerX = d.width / 2;
    int centerY = d.height / 2;
    Calendar now = Calendar.getInstance();

    // Draw the clock shape
    g.setFont(getFont());
    g.setColor(Color.white);
    g.fillArc(0, 0, d.width, d.height, 0, 360);
    g.setColor(Color.black);
    g.drawArc(0, 0, d.width, d.height, 0, 360);

    // draw hour numbers
    g.setColor(getForeground());
    for (int i = 1; i <= 12; i++) {
      double numberTheta = (double) i / 12 * 2 * Math.PI;
      double numberRadius = getEllipseRadius(centerX, centerY, numberTheta);
      int numberX =
          (int)
              (centerX
                  + 0.9 * numberRadius * Math.sin(numberTheta)
                  - g.getFontMetrics().getStringBounds(String.valueOf(i), g).getCenterX());
      int numberY =
          (int)
              (centerY
                  - 0.9 * numberRadius * Math.cos(numberTheta)
                  - g.getFontMetrics().getStringBounds(String.valueOf(i), g).getCenterY());

      g.drawString(String.valueOf(i), numberX, numberY);
    }

    // draw hour markers
    for (int i = 1; i <= 60; i++) {
      double barTheta = (double) i / 60 * 2 * Math.PI;
      double numberRadius = getEllipseRadius(centerX, centerY, barTheta);
      int numberXFull = (int) (centerX + numberRadius * Math.sin(barTheta));
      int numberYFull = (int) (centerY - numberRadius * Math.cos(barTheta));

      g.drawLine(
          (int) (centerX + 0.97 * numberRadius * Math.sin(barTheta)),
          (int) (centerY - 0.97 * numberRadius * Math.cos(barTheta)),
          numberXFull,
          numberYFull);
    }

    // Draw the hour hand
    double hourTheta =
        ((double) now.get(Calendar.HOUR)
                + (double) now.get(Calendar.MINUTE) / 60
                + (double) now.get(Calendar.SECOND) / 3600)
            / 12
            * 2
            * Math.PI;
    double hourRadius = getEllipseRadius(centerX, centerY, hourTheta);
    int hourX = (int) (centerX + 0.5 * hourRadius * Math.sin(hourTheta));
    int hourY = (int) (centerY - 0.5 * hourRadius * Math.cos(hourTheta));
    int hourXOrigin = (int) (centerX - 0.1 * hourRadius * Math.sin(hourTheta));
    int hourYOrigin = (int) (centerY + 0.1 * hourRadius * Math.cos(hourTheta));
    g.setColor(Color.BLACK);
    g.fillArc(hourX - 3, hourY - 3, 6, 6, 0, 360);
    g.drawLine(hourXOrigin, hourYOrigin, hourX, hourY);

    // Draw the minute hand
    double minuteTheta =
        ((double) now.get(Calendar.MINUTE) + (double) now.get(Calendar.SECOND) / 60)
            / 60
            * 2
            * Math.PI;
    double minuteRadius = getEllipseRadius(centerX, centerY, minuteTheta);
    int minuteX = (int) (centerX + 0.8 * minuteRadius * Math.sin(minuteTheta));
    int minuteY = (int) (centerY - 0.8 * minuteRadius * Math.cos(minuteTheta));
    int minuteXOrigin = (int) (centerX - 0.1 * minuteRadius * Math.sin(minuteTheta));
    int minuteYOrigin = (int) (centerY + 0.1 * minuteRadius * Math.cos(minuteTheta));
    g.fillArc(minuteX - 3, minuteY - 3, 6, 6, 0, 360);
    g.drawLine(minuteXOrigin, minuteYOrigin, minuteX, minuteY);

    // Draw the second hand
    double secondTheta = ((double) now.get(Calendar.SECOND)) / 60 * 2 * Math.PI;
    double secondRadius = getEllipseRadius(centerX, centerY, secondTheta);
    int secondX = (int) (centerX + 0.9 * secondRadius * Math.sin(secondTheta));
    int secondY = (int) (centerY - 0.9 * secondRadius * Math.cos(secondTheta));
    int secondXOrigin = (int) (centerX - 0.1 * secondRadius * Math.sin(secondTheta));
    int secondYOrigin = (int) (centerY + 0.1 * secondRadius * Math.cos(secondTheta));
    // redness of second hand getting darker and darker
    g.setColor(
        new Color(
            255,
            199 - (int) (199 * (double) now.get(Calendar.SECOND) / 60),
            199 - (int) (199 * (double) now.get(Calendar.SECOND) / 60)));
    g.fillArc(secondX - 3, secondY - 3, 6, 6, 0, 360);
    g.drawLine(secondXOrigin, secondYOrigin, secondX, secondY);

    // draw the center
    g.setColor(Color.BLACK);
    g.fillArc(centerX - 3, centerY - 3, 6, 6, 0, 360);
  }
Ejemplo n.º 27
0
 public void paint(Graphics g) {
   g.setColor(ourColor);
   g.fillArc(5, 5, 30, 30, 0, 360);
   g.fillArc(25, 5, 30, 30, 0, 360);
   g.fillRect(20, 5, 20, 30);
 }
Ejemplo n.º 28
0
 public void draw_Stone(Graphics g) {
   g.setColor(Color.gray);
   g.fillArc(get_posx(), get_posy(), STONE_RADIUS, STONE_RADIUS, 0, 360);
 }
Ejemplo n.º 29
0
  // drawing of the game happens in here
  // we use the Graphics object, g, to perform the drawing
  // NOTE: This is already double buffered!(helps with framerate/speed)
  @Override
  public void paintComponent(Graphics g) {
    // always clear the screen first!

    // GAME DRAWING GOES HERE

    g.clearRect(0, 0, WIDTH, HEIGHT);

    // custom colours
    Color background = new Color(173, 254, 255);
    Color Skin = new Color(255, 216, 181);
    Color BRown = new Color(163, 82, 28);
    Color ORange = new Color(255, 128, 43);

    // make a background
    g.setColor(background);
    g.fillRect(0, 0, 5000, 5000);
    // make a road
    g.setColor(Color.DARK_GRAY);
    g.fillRect(0, 650, 5000, 5000);

    g.setColor(Color.yellow);
    g.fillRect(10, 740, 30, 10);
    g.fillRect(90, 740, 30, 10);
    g.fillRect(170, 740, 30, 10);
    g.fillRect(250, 740, 30, 10);
    g.fillRect(330, 740, 30, 10);
    g.fillRect(410, 740, 30, 10);
    g.fillRect(490, 740, 30, 10);
    g.fillRect(570, 740, 30, 10);
    g.fillRect(650, 740, 30, 10);
    g.fillRect(730, 740, 30, 10);
    g.fillRect(810, 740, 30, 10);
    g.fillRect(890, 740, 30, 10);
    g.fillRect(970, 740, 30, 10);
    g.fillRect(1050, 740, 30, 10);
    g.fillRect(1130, 740, 30, 10);
    g.fillRect(1193, 740, 30, 10);

    // make rain
    g.setColor(Color.blue);
    for (int i = 0; i < rainX.length; i++) {
      g.fillRect(rainX[i], rainY[i], 10, 20);
    }

    // make face

    g.setColor(ORange);
    // body
    g.fillRect(475, 540, 250, 170);
    g.fillArc(450, 450, 300, 400, 0, 180);
    // hands
    g.fillOval(439, 630, 50, 50);
    g.fillOval(707, 630, 50, 50);
    g.setColor(Color.red);
    g.drawOval(460, 630, 25, 25);
    g.drawOval(707, 630, 25, 25);
    g.setColor(Color.black);
    // pockets
    // right pocket
    g.drawLine(718, 630, 715, 600);
    g.drawLine(719, 630, 716, 600);
    // left pocket
    g.drawLine(472, 630, 475, 600);
    g.drawLine(473, 630, 476, 600);
    // zipper
    g.drawLine(595, 500, 595, 650);
    g.drawLine(596, 500, 596, 650);
    g.drawLine(597, 500, 597, 650);
    g.drawLine(598, 500, 598, 650);

    // black outline of head
    g.fillOval(450, 251, 300, 300);
    g.setColor(ORange);
    // black border around face
    g.fillOval(449, 250, 303, 299);
    g.setColor(Color.BLACK);
    g.fillOval(500, 300, 200, 200);
    g.setColor(ORange);
    g.fillOval(504, 303, 193, 193);

    // border around face
    g.setColor(BRown);
    g.fillOval(513, 302, 175, 175);

    // make face
    g.setColor(Skin);

    g.fillArc(527, 315, 150, 150, -90, 180);
    g.fillArc(528, 315, 150, 150, 270, -180);

    // make eyes
    g.setColor(Color.WHITE);
    g.fillOval(528, 348, 75, 75);
    g.fillOval(600, 350, 75, 75);

    g.setColor(Color.BLACK);
    g.fillOval(609, 379, 10, 10);
    g.fillOval(585, 378, 10, 10);

    // make Feet
    g.fillArc(464, 700, 140, 30, 0, 180);
    g.fillArc(595, 700, 140, 30, 0, 180);

    // make bullet
    g.fillArc(bullet, 350, 40, 40, -90, 180);

    // make bullet mover towards kenny
    bullet++;

    // when the bullet hits kenny make screen go blank
    if (timer > 416 || bullet > 426) {
      g.setColor(Color.red);
      g.fillRect(0, 0, 1200, 850);
    }

    if (timer > 420 || bullet >= 435) {
      g.setColor(Color.black);
      g.fillRect(0, 0, 1200, 850);
    }

    // when screen goes blank reset the scene
    if (timer > 425) {
      timer = 0;
      bullet = 0;
    }

    // GAME DRAWING ENDS HERE
  }