// draws the button, based on the type of button (ImageIcon, Image, or String)
  public void draw(Graphics g) {
    if (visible) {
      // if its image/imageicon, draw it
      g.setColor(new Color(50, 200, 50));
      g.fillRect(x - 1, y - 1, width + 2, height + 2);
      if (mode.equals("Image") || mode.equals("ImageIcon")) {
        if (enabled) {
          g.drawImage(image, x, y, null);
        } else {
          g.drawImage(BWimage, x, y, null);
        }
        // if its string, draw the string
      } else {

        g.setFont(new Font("Arial", Font.PLAIN, 20));
        if (enabled) {
          g.setColor(Color.black);
          g.drawString(message, x + 20, y + 20);
        } else {
          g.setColor(new Color(255, 255, 255));
          g.fillRect(x - 1, y - 1, width + 2, height + 2);
          g.setColor(Color.black);
          g.drawString(message, x + 20, y + 20);
        }
      }
    }
  }
Beispiel #2
0
  /**
   * Draws the specified string.
   *
   * @param g graphics reference
   * @param s text
   * @param x x coordinate
   * @param y y coordinate
   * @param w width
   * @param fs font size
   */
  public static void chopString(
      final Graphics g, final byte[] s, final int x, final int y, final int w, final int fs) {

    if (w < 12) return;
    final int[] cw = fontWidths(g.getFont());

    int j = s.length;
    try {
      int l = 0;
      int fw = 0;
      for (int k = 0; k < j; k += l) {
        final int ww = width(g, cw, cp(s, k));
        if (fw + ww >= w - 4) {
          j = Math.max(1, k - l);
          if (k > 1) fw -= width(g, cw, cp(s, k - 1));
          g.drawString("..", x + fw, y + fs);
          break;
        }
        fw += ww;
        l = cl(s, k);
      }
    } catch (final Exception ex) {
      Util.debug(ex);
    }
    g.drawString(string(s, 0, j), x, y + fs);
  }
Beispiel #3
0
  public void paint(Graphics g) {
    g.setColor(Color.red);
    g.fillRect(xpos1, ypos1, width, length);

    g.setColor(Color.blue);
    g.fillRect(xpos2, ypos2, width, length);

    g.setColor(Color.green);
    g.fillOval(x_pos - radius, y_pos - radius, 2 * radius, 2 * radius);

    Font text = new Font("Arial", Font.BOLD, 16);
    setFont(text);
    g.setColor(Color.white);
    g.drawString("Pong v. 1.0", 200, 25);

    message1 = "Player 1 Score: " + score1;
    message2 = "Player 2 Score: " + score2;

    g.drawString(message1, 10, 30);
    g.drawString(message2, 325, 30);

    if ((score1 == 10) || (score2 == 10)) {
      g.drawString(gameover, 175, 250);
    }
  }
Beispiel #4
0
  private void drawAxes(Graphics g) {
    g.drawLine(padding, height, width + padding, height);
    g.drawLine(padding, 0, padding, height);

    g.drawString("time", padding + width / 2, height + padding - 5);
    g.drawString("pop", 5, height / 2);
  }
Beispiel #5
0
    public void paintComponent(Graphics g) {
      g.setColor(new Color(96, 96, 96));
      image.paintIcon(this, g, 1, 1);

      FontMetrics fm = g.getFontMetrics();

      String[] args = {jEdit.getVersion()};
      String version = jEdit.getProperty("about.version", args);
      g.drawString(version, (getWidth() - fm.stringWidth(version)) / 2, getHeight() - 5);

      g = g.create((getWidth() - maxWidth) / 2, TOP, maxWidth, getHeight() - TOP - BOTTOM);

      int height = fm.getHeight();
      int firstLine = scrollPosition / height;

      int firstLineOffset = height - scrollPosition % height;
      int lines = (getHeight() - TOP - BOTTOM) / height;

      int y = firstLineOffset;

      for (int i = 0; i <= lines; i++) {
        if (i + firstLine >= 0 && i + firstLine < text.size()) {
          String line = (String) text.get(i + firstLine);
          g.drawString(line, (maxWidth - fm.stringWidth(line)) / 2, y);
        }
        y += fm.getHeight();
      }
    }
Beispiel #6
0
  private void drawYTicks(Graphics g) {
    int hPos = 0;
    int pPos = 0;
    for (int i = 0; i < yTicks; i++) {
      int drawPos = yVal(hPos, maxH) + r;

      if (hPos % hInc == 0) {

        // draw line
        g.setColor(Color.BLACK);
        g.drawLine(padding - 10, drawPos, padding, drawPos);

        // draw tick values for herbivores
        g.setColor(Color.BLUE);
        g.drawString("" + hPos, padding - 50, drawPos + r);

        // draw tick values for predators
        g.setColor(Color.RED);
        g.drawString("" + pPos, padding - 50, drawPos + r + 20);
      }

      hPos += hInc;
      pPos += pInc;
    }
  }
 public void displayScore2(
     Graphics g, int cx, int cy, int sx1, int sy1, int sx2, int sy2, int sx3, int sy3) {
   g.setFont(scoreFont);
   g.setColor(Color.WHITE);
   g.drawImage(new ImageIcon("InGameMenu/coin.png").getImage(), cx, cy, this);
   g.drawString("" + coins, sx1, sy1);
   g.drawString("Score:  " + score, sx2, sy2);
   g.drawString("Height:  " + height + " m", sx3, sy3);
 }
Beispiel #8
0
  public void draw(Graphics g) {
    g.setColor(Color.BLACK);
    g.drawString("Points: " + points, 10, 20);
    g.drawString("Lives: " + lives, 10, 30);
    if (lives <= 0) {
      g.setColor(Color.RED);
      g.drawString("You Lose", WIDTH / 2 - 20, HEIGHT / 2);
    }
    for (int i = 0; i < balls.size(); i++) balls.get(i).draw(g);

    bucket.draw(g);
  }
 public static DrawingPanel background(String meaning) {
   DrawingPanel panel = new DrawingPanel(780, 560);
   Graphics g = panel.getGraphics();
   panel.setBackground(Color.white);
   g.setColor(Color.LIGHT_GRAY);
   g.fillRect(0, 0, 781, bannerHeight);
   g.fillRect(0, 530, 781, bannerHeight);
   g.setColor(Color.black);
   g.drawString(meaning, 0, 16);
   for (int i = startYear; i <= 2010; i += 10) {
     g.drawString("" + i, (decadeWidth / 10) * (i - startYear), 552);
   }
   return panel;
 }
    private void displayTree(Graphics g, AVLTree.TreeNode root, int x, int y, int gap) {
      if (root != null) {
        // Display root
        if (setOfHighlightedNodes.contains(root)) {
          g.setColor(Color.GREEN);
          g.fillOval(x - radius, y - radius, 2 * radius, 2 * radius);
          g.setColor(Color.BLACK);
        } else {
          g.drawOval(x - radius, y - radius, 2 * radius, 2 * radius);
        }

        g.drawString(root.element + "", x - 6, y + 4);

        // Draw a line to the left node
        if (root.left != null) connectLeftChild(g, x - gap, y + virticalGap, x, y);

        // Draw left subtree
        displayTree(g, root.left, x - gap, y + virticalGap, gap / 2);

        // Draw a line to the right node
        if (root.right != null) connectRightChild(g, x + gap, y + virticalGap, x, y);

        // Draw right subtree
        displayTree(g, root.right, x + gap, y + virticalGap, gap / 2);
      }
    }
Beispiel #11
0
  public void paintComponent(Graphics graphics) {
    Rectangle bounds = getBounds();
    GraphicsUtility graphicsUtility = new GraphicsUtility(graphics);
    graphicsUtility.setStroke(GraphicsUtility.STROKE_BOLD);

    if (isSelected()) {
      graphics.setColor(GraphicsUtility.getSelectedColor());
      graphics.fillRect(0, 0, bounds.width, SELECT_BORDER_SIZE);
      graphics.fillRect(0, 0, SELECT_BORDER_SIZE, bounds.height);
      graphics.fillRect(0, bounds.height - SELECT_BORDER_SIZE, bounds.width, SELECT_BORDER_SIZE);
      graphics.fillRect(bounds.width - SELECT_BORDER_SIZE, 0, SELECT_BORDER_SIZE, bounds.height);
      graphics.setColor(Color.BLACK);
    }
    graphics.drawString(getCaption(), 10, 10);

    graphicsUtility.drawArrow(
        8, BORDER_INSET, BORDER_INSET, BORDER_INSET, bounds.height - BORDER_INSET);
    graphicsUtility.drawArrow(
        8,
        BORDER_INSET,
        bounds.height - BORDER_INSET,
        bounds.width - BORDER_INSET,
        bounds.height - BORDER_INSET);
    graphicsUtility.drawArrow(
        8,
        bounds.width - BORDER_INSET,
        bounds.height - BORDER_INSET,
        bounds.width - BORDER_INSET,
        BORDER_INSET);
    graphicsUtility.drawArrow(
        8, bounds.width - BORDER_INSET, BORDER_INSET, bounds.width - 50, BORDER_INSET);
    graphicsUtility.setStroke(GraphicsUtility.STROKE_NORMAL);
  }
 void drawRoiLabel(Graphics g, int index, Roi roi) {
   Rectangle r = roi.getBounds();
   int x = screenX(r.x);
   int y = screenY(r.y);
   double mag = getMagnification();
   int width = (int) (r.width * mag);
   int height = (int) (r.height * mag);
   int size = width > 40 && height > 40 ? 12 : 9;
   if (font != null) {
     g.setFont(font);
     size = font.getSize();
   } else if (size == 12) g.setFont(largeFont);
   else g.setFont(smallFont);
   boolean drawingList = index >= LIST_OFFSET;
   if (drawingList) index -= LIST_OFFSET;
   String label = "" + (index + 1);
   if (drawNames && roi.getName() != null) label = roi.getName();
   FontMetrics metrics = g.getFontMetrics();
   int w = metrics.stringWidth(label);
   x = x + width / 2 - w / 2;
   y = y + height / 2 + Math.max(size / 2, 6);
   int h = metrics.getAscent() + metrics.getDescent();
   if (bgColor != null) {
     g.setColor(bgColor);
     g.fillRoundRect(x - 1, y - h + 2, w + 1, h - 3, 5, 5);
   }
   if (!drawingList && labelRects != null && index < labelRects.length)
     labelRects[index] = new Rectangle(x - 1, y - h + 2, w + 1, h);
   g.setColor(labelColor);
   g.drawString(label, x, y - 2);
   g.setColor(defaultColor);
 }
Beispiel #13
0
  /** Affichage du logo */
  protected void drawLogo(Graphics g) {

    int x = 5;
    int y = 2;

    g.setColor(getBackground());
    g.fillRect(0, 0, W, H);

    // Remplissage
    fillBG(g, x, y, Color.white);

    // Dessin
    drawGrid(
        g,
        x,
        y,
        !isAvailable()
            ? Aladin.MYGRAY
            : isActive() ? Aladin.GREEN : isMouseIn() ? Color.blue : Color.black);

    // Label
    g.setColor(isAvailable() ? Color.black : Aladin.MYGRAY);
    g.setFont(Aladin.SPLAIN);
    g.drawString(LABEL, W / 2 - g.getFontMetrics().stringWidth(LABEL) / 2, H - 2);
  }
  public void draw(Graphics g) {
    animate();

    g.setColor(Color.black);
    g.fillRect(0, 0, dim.width, dim.height);
    g.setColor(Color.white);

    numpaint++;
    DebugPrinter dbg = new DebugPrinter(g, 50, 60);
    dbg.print(
        "Spring-mass demo by yigal irani, drag balls or create new ones by clicking inside box");
    dbg.print("frame", numpaint);
    dbg.print("fps", 1 / timer.time_diff);

    Point top_left = point_by_vec(new Vec(-1, 1));
    g.draw3DRect(top_left.x, top_left.y, screen_dist(2), screen_dist(2), true);
    for (int i = 0; i < springs.size(); i++) {
      Spring spring = springs.get2(i);
      Point p1 = point_by_vec(balls.get2(spring.start).pos);
      Point p2 = point_by_vec(balls.get2(spring.end).pos);
      g.drawLine(p1.x, p1.y, p2.x, p2.y);
    }
    for (int i = 0; i < balls.size(); i++) {
      Ball ball = balls.get2(i);
      Point p = point_by_vec(ball.pos);
      int screen_radius = screen_dist(RADIUS);
      g.setColor(Color.blue);
      g.fillOval(p.x - screen_radius, p.y - screen_radius, screen_radius * 2, screen_radius * 2);

      g.setColor(Color.white);
      g.drawOval(p.x - screen_radius, p.y - screen_radius, screen_radius * 2, screen_radius * 2);

      g.drawString("" + i, p.x, p.y);
    }
  }
Beispiel #15
0
  public void paint(Graphics g) {
    m_fm = g.getFontMetrics();

    g.setColor(getBackground());
    g.fillRect(0, 0, getWidth(), getHeight());
    getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight());

    g.setColor(getForeground());
    g.setFont(getFont());
    m_insets = getInsets();
    int x = m_insets.left;
    int y = m_insets.top + m_fm.getAscent();

    StringTokenizer st = new StringTokenizer(getText(), "\t");
    while (st.hasMoreTokens()) {
      String sNext = st.nextToken();
      g.drawString(sNext, x, y);
      x += m_fm.stringWidth(sNext);

      if (!st.hasMoreTokens()) break;
      int index = 0;
      while (x >= getTab(index)) index++;
      x = getTab(index);
    }
  }
 public void paint(Graphics g) {
   g.drawRect(x[0], y[0], 40, 40);
   g.fillRect(x[1], y[1], 20, 20);
   g.drawLine(x[2], y[2], x[3], y[3]);
   g.drawOval(x[4], y[4], 20, 30);
   g.drawString("Moveing", x[5], y[5]);
 }
Beispiel #17
0
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Dimension d = getSize();

    if (d.width != maxWidth || d.height != textHeight) recalculateDimension();

    Insets insets = this.getInsets();

    int y = 0;

    if (verticalAlignment == TOP) {
      y = insets.top + lineAscent;
    } else if (verticalAlignment == CENTER) {
      // These two are must musts:
      y = insets.top + lineAscent;

      // So far it looks like the TOP case, BUT:
      int clientAreaHeight = d.height - insets.top - insets.bottom;
      y = y + (clientAreaHeight - textHeight) / 2;
    } else if (verticalAlignment == BOTTOM) {
      int clientAreaBottom = d.height - insets.bottom;

      y = clientAreaBottom - textHeight;

      y += lineAscent;
    }

    for (int i = 0; i < numLines; i++) {
      int ha = getBidiHorizontalAlignment(horizontalAlignment);

      int x = 0;

      if (ha == LEFT) {
        ha = getBidiHorizontalAlignment(textAlignment);
        if (ha == LEFT) x = insets.left;
        else if (ha == RIGHT) x = maxWidth - lineWidths[i] + insets.left;
        else if (ha == CENTER) x = insets.left + (maxWidth - lineWidths[i]) / 2;
      } else if (ha == RIGHT) {
        ha = getBidiHorizontalAlignment(textAlignment);
        if (ha == LEFT) x = d.width - maxWidth - insets.right;
        else if (ha == RIGHT) x = d.width - lineWidths[i] - insets.right;
        else if (ha == CENTER)
          x = d.width - maxWidth - insets.right + (maxWidth - lineWidths[i]) / 2;
      } else if (ha == CENTER) {
        ha = getBidiHorizontalAlignment(textAlignment);

        // Just imagine that ha=LEFT (much easier), and follow code
        int clientAreaWidth = d.width - insets.left - insets.right;
        if (ha == LEFT) x = insets.left + (clientAreaWidth - maxWidth) / 2;
        else if (ha == RIGHT)
          x = insets.left + (clientAreaWidth - maxWidth) / 2 + (maxWidth - lineWidths[i]);
        else if (ha == CENTER) x = insets.left + (clientAreaWidth - lineWidths[i]) / 2;
      }
      x += btnMarginWidth;
      g.drawString(lines[i], x, y);

      y += lineHeight;
    }
  }
Beispiel #18
0
 void drawLabel(Graphics g, DrawObject L) {
   if ((sequencingOn) && (L.sequenceNum != currentSequenceNumDisplay)) {
     return;
   }
   int x = (int) ((L.x - minX) / (maxX - minX) * (D.width - 2 * inset));
   int y = (int) ((L.y - minY) / (maxY - minY) * (D.height - 2.0 * inset));
   g.drawString(L.str, inset + x, D.height - y - inset);
 }
Beispiel #19
0
  public void paint(Graphics g) {
    super.paint(g);

    Dimension size = getSize();
    double w = size.getWidth() - 50;
    double h = size.getHeight() + 20;

    try {
      readFile();
    } catch (IOException e) {
      System.err.println("IO issue");
    }

    barWidth = ((int) (w / numBars)) - 20;
    pos = 5;

    int xPos[] = {pos, pos, pos, pos};
    int yPos[] = {pos, pos, pos, pos};

    maxVal = maxValue(values);
    double barH, ratio;

    for (int i = 0; i < numBars - 1; i++) {
      Color col[] = new Color[numBars];
      for (int j = 0; j < numBars - 1; j++) {
        col[j] = new Color((int) (Math.random() * 0x1000000));
      }

      ratio = (double) values[i] / (double) maxVal;
      barH = ((h) * ratio) - 10;

      xPos[0] = pos;
      xPos[2] = pos + barWidth;
      xPos[1] = xPos[0];
      xPos[3] = xPos[2];
      yPos[0] = (int) h;
      yPos[1] = (int) barH;
      yPos[2] = yPos[1];
      yPos[3] = yPos[0];

      System.out.println(
          "xPos:" + xPos[1] + " yPos:" + yPos[0] + " h:" + h + " barH:" + barH + " ratio:" + ratio
              + " pos:" + pos);

      int stringPtsY[] = {
        ((i + 1) * 20) + 180, ((i + 1) * 20) + 200, ((i + 1) * 20) + 200, ((i + 1) * 20) + 180
      };
      int stringPtsX[] = {600, 600, 580, 580};

      g.setColor(col[i]);
      g.fillPolygon(xPos, yPos, xPos.length);

      g.fillPolygon(stringPtsX, stringPtsY, 4);
      g.setColor(Color.black);
      g.drawString(labels[i], 610, ((i + 1) * 20) + 195);
      pos = pos + barWidth + 10;
    }
  }
Beispiel #20
0
  public void Message(String s1, String s2, int i) {
    Graphics g = getGraphics();

    if (s1 == null || s2 == null) {
      g.setColor(bgcolor);
      g.drawRect(400, 50 * i - 10, 200, 20);
      g.fillRect(400, 50 * i - 10, 200, 20);
      return;
    }
    /*
      g.setColor(Color.blue);
      g.drawRect(400,50 * i - 10,200,20);
      g.fillRect(400,50 * i - 10,200,20);
    */
    g.setColor(txtcolor);
    g.drawString(s1, 400, 50 * i);
    g.drawString(s2, 400, 50 * i + 10);
  }
 void displayStatus(Graphics g) {
   if (statusString != null) {
     g.setColor(0xffffff);
     g.fillRect(0, getHeight() - inputHeight - 2, getWidth(), inputHeight + 2);
     g.setColor(0x000000);
     g.drawLine(0, getHeight() - inputHeight - 2, getWidth(), getHeight() - inputHeight - 2);
     g.drawString(statusString, 0, getHeight() - inputHeight - 2, Graphics.LEFT | Graphics.TOP);
   }
 }
Beispiel #22
0
 public void paintComponent(Graphics g) {
   if (position == null) return;
   int x = (int) position.getX();
   int y = (int) position.getY();
   if (parent.inFirstPath(this)) {
     g.setColor(Color.yellow);
     g.fillOval(x - RADIUS, y - RADIUS, 2 * RADIUS, 2 * RADIUS);
   } else if (parent.inQueue(this)) {
     g.setColor(Color.orange);
     g.fillOval(x - RADIUS, y - RADIUS, 2 * RADIUS, 2 * RADIUS);
   }
   g.setColor(getColor());
   g.drawOval(x - RADIUS, y - RADIUS, 2 * RADIUS, 2 * RADIUS);
   if (parent.isGoalNode(this)) g.setColor(Color.green);
   else if (parent.isStartNode(this)) g.setColor(Color.blue);
   g.drawString(toString(), x, y);
   if (!parent.getHideHeur()) g.drawString(model.getHeuristic() + "", x + RADIUS, y + RADIUS);
 }
  public void paint(Graphics g) {
    g.setFont(getFont());

    Color boxColor = getBackgroundBoxColor();
    Color hatchColor = getHatchColor();
    Color backgroundLineColor = getBackgroundLineColor();
    //    Color textColor = getForeground();
    int outlineType = getOutlineType();
    Color outlineColor = getOutlineColor();

    if (backgroundLineColor != null) {
      g.setColor(backgroundLineColor);
      g.fillRect(0, getSize().height / 2 - 1, getSize().width, 2);
    }

    if (boxColor != null) {
      g.setColor(boxColor);
      g.fillRect(0, 0, getSize().width, getSize().height);
    }

    if (hatchColor != null) {
      g.setColor(hatchColor);

      // Bev thinks the cross-hatching makes it too hard to read the base.
      // For a single diagonal line, replace the following three lines with
      // g.drawLine(0,getSize().height, getSize().width,0);
      // For an underline, replace with
      // g.drawLine(0,getSize().height, getSize().width,getSize().height);

      // Draw three cross-hatch lines
      // g.drawLine(0,0,getSize().width,getSize().height);
      // g.drawLine(getSize().width/2,0,getSize().width,getSize().height/2);
      // g.drawLine(0,getSize().height/2,getSize().width/2,getSize().height);

      // Draw a line at top and bottom of matching base
      g.drawLine(0, getSize().height, getSize().width, getSize().height); // bottom
      g.drawLine(0, 0, getSize().width, 0); // top
      //      g.drawLine(0,0, 0,getSize().height);  // left side
      //      g.drawLine(getSize().width,0, getSize().width,getSize().height);  // right side
    }

    if (outlineType != NO_OUTLINE && outlineColor != null) {
      g.setColor(outlineColor);
      g.drawLine(0, 0, getSize().width - 1, 0);
      g.drawLine(0, getSize().height - 1, getSize().width - 1, getSize().height - 1);
      if (outlineType == LEFT_OUTLINE) g.drawLine(0, 0, 0, getSize().height - 1);
      else if (outlineType == RIGHT_OUTLINE) {
        g.drawLine(getSize().width - 1, 0, getSize().width - 1, getSize().height - 1);
      }
    }

    if (getTextColor() != null) {
      int leadDistance = (getSize().width - metrics.charWidth(c)) / 2;
      g.setColor(getTextColor());
      g.drawString(c + "", leadDistance, getSize().height - 2);
    }
  }
Beispiel #24
0
 public void paint(Graphics g) {
   Dimension d = getSize();
   int j = line_ascent + btnMarginHeight;
   for (int k = 0; k < num_lines; k++) {
     int i = (d.width - line_widths[k]) / 2;
     g.drawString(lines[k], i, j);
     j += line_height;
   }
   if (btnPlacement == 1 || btnPlacement == 2) setSize(d.width, max_height);
 }
Beispiel #25
0
 /**
  * Draws a visualization tooltip.
  *
  * @param g graphics reference
  * @param tt tooltip label
  * @param x horizontal position
  * @param y vertical position
  * @param w width
  * @param c color color depth
  */
 public static void drawTooltip(
     final Graphics g, final String tt, final int x, final int y, final int w, final int c) {
   final int tw = width(g, tt);
   final int th = g.getFontMetrics().getHeight();
   final int xx = Math.min(w - tw - 8, x);
   g.setColor(color(c));
   g.fillRect(xx - 1, y - th, tw + 4, th);
   g.setColor(BACK);
   g.drawString(tt, xx, y - 4);
 }
 void displayCurrentCommand(Graphics g) {
   g.setColor(0xffffff);
   g.fillRect(0, getHeight() - inputHeight - 2, getWidth(), inputHeight + 2);
   g.setColor(0x000000);
   g.drawLine(0, getHeight() - inputHeight - 2, getWidth(), getHeight() - inputHeight - 2);
   g.drawString(
       "Ctrl" + " + " + currentCharCommand,
       0,
       getHeight() - inputHeight,
       Graphics.LEFT | Graphics.TOP);
 }
Beispiel #27
0
 public void paint(Graphics canvas) {
   m_bClash = false;
   DrawSquares(canvas);
   canvas.setColor(Color.RED);
   CheckColumns(canvas);
   CheckRows(canvas);
   CheckDiagonal1(canvas);
   CheckDiagonal2(canvas);
   canvas.setColor(Color.BLUE);
   canvas.drawString(m_strStatus, BOARDLEFT, BOARDTOP + SQUAREHEIGHT * 8 + 20);
 }
Beispiel #28
0
  @Override
  /** Draw the clock */
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    // Initialize clock parameters
    int clockRadius = (int) (Math.min(getWidth(), getHeight()) * 0.8 * 0.5);
    int xCenter = getWidth() / 2;
    int yCenter = getHeight() / 2;

    // Draw circle
    g.setColor(Color.black);
    g.drawOval(xCenter - clockRadius, yCenter - clockRadius, 2 * clockRadius, 2 * clockRadius);
    g.drawString("12", xCenter - 5, yCenter - clockRadius + 12);
    g.drawString("9", xCenter - clockRadius + 3, yCenter + 5);
    g.drawString("3", xCenter + clockRadius - 10, yCenter + 3);
    g.drawString("6", xCenter - 3, yCenter + clockRadius - 3);

    // Draw second hand
    int sLength = (int) (clockRadius * 0.8);
    int xSecond = (int) (xCenter + sLength * Math.sin(second * (2 * Math.PI / 60)));
    int ySecond = (int) (yCenter - sLength * Math.cos(second * (2 * Math.PI / 60)));
    g.setColor(Color.red);
    g.drawLine(xCenter, yCenter, xSecond, ySecond);

    // Draw minute hand
    int mLength = (int) (clockRadius * 0.65);
    int xMinute = (int) (xCenter + mLength * Math.sin(minute * (2 * Math.PI / 60)));
    int yMinute = (int) (yCenter - mLength * Math.cos(minute * (2 * Math.PI / 60)));
    g.setColor(Color.blue);
    g.drawLine(xCenter, yCenter, xMinute, yMinute);

    // Draw hour hand
    int hLength = (int) (clockRadius * 0.5);
    int xHour =
        (int) (xCenter + hLength * Math.sin((hour % 12 + minute / 60.0) * (2 * Math.PI / 12)));
    int yHour =
        (int) (yCenter - hLength * Math.cos((hour % 12 + minute / 60.0) * (2 * Math.PI / 12)));
    g.setColor(Color.green);
    g.drawLine(xCenter, yCenter, xHour, yHour);
  }
Beispiel #29
0
 /**
  * Draws this process as a colored box with a process ID inside.
  *
  * @param g The graphics context.
  * @param x The leftmost x-coordinate of the box.
  * @param y The topmost y-coordinate of the box.
  * @param w The width of the box.
  * @param h The height of the box.
  */
 public void draw(Graphics g, int x, int y, int w, int h) {
   g.setColor(color);
   g.fillRect(x, y, w, h);
   g.setColor(Color.black);
   g.drawRect(x, y, w, h);
   g.setFont(font);
   FontMetrics fm = g.getFontMetrics(font);
   g.drawString(
       "" + processId,
       x + w / 2 - fm.stringWidth("" + processId) / 2,
       y + h / 2 + fm.getHeight() / 2);
 }
Beispiel #30
0
  /** This internal method begins a new page and prints the header. */
  protected void newpage() {
    page = job.getGraphics(); // Begin the new page
    linenum = 0;
    charnum = 0; // Reset line and char number
    pagenum++; // Increment page number
    page.setFont(headerfont); // Set the header font.
    page.drawString(jobname, x0, headery); // Print job name left justified

    String s = "- " + pagenum + " -"; // Print the page number centered.
    int w = headermetrics.stringWidth(s);
    page.drawString(s, x0 + (this.width - w) / 2, headery);
    w = headermetrics.stringWidth(time); // Print date right justified
    page.drawString(time, x0 + width - w, headery);

    // Draw a line beneath the header
    int y = headery + headermetrics.getDescent() + 1;
    page.drawLine(x0, y, x0 + width, y);

    // Set the basic monospaced font for the rest of the page.
    page.setFont(font);
  }