// Show a message over frozen image in the display
 public void showMessage(String message) {
   Graphics g = getGraphics();
   g.setColor(Color.black);
   g.fillRect(30, (getHeight() / 2) - 16, message.length() * 10, 25);
   g.setColor(Color.white);
   g.drawString(message, 40, getHeight() / 2);
 }
예제 #2
0
 private static ImageIcon makeGrayImageIcon1(Image img) {
   BufferedImage source =
       new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
   Graphics g = source.createGraphics();
   g.drawImage(img, 0, 0, null);
   g.dispose();
   ColorConvertOp colorConvert =
       new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
   BufferedImage destination = colorConvert.filter(source, null);
   return new ImageIcon(destination);
 }
예제 #3
0
 private static ImageIcon makeGrayImageIcon2(Image img) {
   int w = img.getWidth(null);
   int h = img.getHeight(null);
   BufferedImage destination = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_GRAY);
   Graphics g = destination.createGraphics();
   //// g.setColor(Color.WHITE);
   // https://community.oracle.com/thread/1373262 Color to Grayscale to Binary
   // g.fillRect(0, 0, w, h); // need to pre-fill(alpha?)
   g.drawImage(img, 0, 0, null);
   g.dispose();
   return new ImageIcon(destination);
 }
예제 #4
0
  @Override
  public void paintIcon(Component c, Graphics g, int x, int y) {
    if (image == null) {
      image = new BufferedImage(getIconWidth(), getIconHeight(), BufferedImage.TYPE_INT_ARGB);
      double coef = Math.min((double) width / (double) 68, (double) height / (double) 81);

      Graphics2D g2d = image.createGraphics();
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g2d.scale(coef, coef);
      paint(g2d);
      g2d.dispose();
    }

    g.drawImage(image, x, y, null);
  }
예제 #5
0
 public static void fillCircle(Graphics g, int x, int y, int radius) {
   int x1 = x - radius;
   int y1 = y - radius;
   g.fillOval(x1, y1, radius * 2 + 1, radius * 2 + 1);
 }
예제 #6
0
    public void paint(Graphics g) {

      if (big == null) {
        return;
      }

      big.setBackground(getBackground());
      big.clearRect(0, 0, w, h);

      float freeMemory = (float) r.freeMemory();
      float totalMemory = (float) r.totalMemory();

      // .. Draw allocated and used strings ..
      big.setColor(GREEN);
      big.drawString(
          String.valueOf((int) totalMemory / 1024) + "K allocated", 4.0f, (float) ascent + 0.5f);
      usedStr = String.valueOf(((int) (totalMemory - freeMemory)) / 1024) + "K used";
      big.drawString(usedStr, 4, h - descent);

      // Calculate remaining size
      float ssH = ascent + descent;
      float remainingHeight = (float) (h - (ssH * 2) - 0.5f);
      float blockHeight = remainingHeight / 10;
      float blockWidth = 20.0f;
      float remainingWidth = (float) (w - blockWidth - 10);

      // .. Memory Free ..
      big.setColor(mfColor);
      int MemUsage = (int) ((freeMemory / totalMemory) * 10);
      int i = 0;
      for (; i < MemUsage; i++) {
        mfRect.setRect(5, (float) ssH + i * blockHeight, blockWidth, (float) blockHeight - 1);
        big.fill(mfRect);
      }

      // .. Memory Used ..
      big.setColor(GREEN);
      for (; i < 10; i++) {
        muRect.setRect(5, (float) ssH + i * blockHeight, blockWidth, (float) blockHeight - 1);
        big.fill(muRect);
      }

      // .. Draw History Graph ..
      big.setColor(graphColor);
      int graphX = 30;
      int graphY = (int) ssH;
      int graphW = w - graphX - 5;
      int graphH = (int) remainingHeight;
      graphOutlineRect.setRect(graphX, graphY, graphW, graphH);
      big.draw(graphOutlineRect);

      int graphRow = graphH / 10;

      // .. Draw row ..
      for (int j = graphY; j <= graphH + graphY; j += graphRow) {
        graphLine.setLine(graphX, j, graphX + graphW, j);
        big.draw(graphLine);
      }

      // .. Draw animated column movement ..
      int graphColumn = graphW / 15;

      if (columnInc == 0) {
        columnInc = graphColumn;
      }

      for (int j = graphX + columnInc; j < graphW + graphX; j += graphColumn) {
        graphLine.setLine(j, graphY, j, graphY + graphH);
        big.draw(graphLine);
      }

      --columnInc;

      if (pts == null) {
        pts = new int[graphW];
        ptNum = 0;
      } else if (pts.length != graphW) {
        int tmp[] = null;
        if (ptNum < graphW) {
          tmp = new int[ptNum];
          System.arraycopy(pts, 0, tmp, 0, tmp.length);
        } else {
          tmp = new int[graphW];
          System.arraycopy(pts, pts.length - tmp.length, tmp, 0, tmp.length);
          ptNum = tmp.length - 2;
        }
        pts = new int[graphW];
        System.arraycopy(tmp, 0, pts, 0, tmp.length);
      } else {
        big.setColor(YELLOW);
        pts[ptNum] = (int) (graphY + graphH * (freeMemory / totalMemory));
        for (int j = graphX + graphW - ptNum, k = 0; k < ptNum; k++, j++) {
          if (k != 0) {
            if (pts[k] != pts[k - 1]) {
              big.drawLine(j - 1, pts[k - 1], j, pts[k]);
            } else {
              big.fillRect(j, pts[k], 1, 1);
            }
          }
        }
        if (ptNum + 2 == pts.length) {
          // throw out oldest point
          for (int j = 1; j < ptNum; j++) {
            pts[j - 1] = pts[j];
          }
          --ptNum;
        } else {
          ptNum++;
        }
      }
      g.drawImage(bimg, 0, 0, this);
    }