List of usage examples for java.awt Graphics setColor
public abstract void setColor(Color c);
From source file:SineDraw.java
public void paintComponent(Graphics g) { super.paintComponent(g); int maxWidth = getWidth(); double hstep = (double) maxWidth / (double) points; int maxHeight = getHeight(); pts = new int[points]; for (int i = 0; i < points; i++) pts[i] = (int) (sines[i] * maxHeight / 2 * .95 + maxHeight / 2); g.setColor(Color.RED); for (int i = 1; i < points; i++) { int x1 = (int) ((i - 1) * hstep); int x2 = (int) (i * hstep); int y1 = pts[i - 1]; int y2 = pts[i]; g.drawLine(x1, y1, x2, y2);/*from w w w . j a v a 2 s . c om*/ } }
From source file:Arrow.java
public void paintIcon(Component c, Graphics g, int x, int y) { Color color = c == null ? Color.GRAY : c.getBackground(); int dx = (int) (size / 2); int dy = descending ? dx : -dx; // Align icon (roughly) with font baseline. y = y + 5 * size / 6 + (descending ? -dy : 0); g.translate(x, y);/*w ww . j av a 2 s. c o m*/ g.setColor(Color.GRAY); g.fillPolygon(new int[] { dx / 2, dx, 0 }, new int[] { dy, 0, 0 }, 3); g.translate(-x, -y); g.setColor(color); }
From source file:edu.upf.bioevo.manhattanPlotter.QQPlot.java
void drawPlot() { int dotRadius; int xIncrement = (IMAGE_WIDTH - (xMargin * 2)) / (int) (maxExpectedLogValue + 1); int yIncrement = (IMAGE_HEIGHT - (yMargin * 2)) / (int) (maxObservedLogValue + 1); Graphics g = image.getGraphics(); // Cleans image g.setColor(Color.WHITE); g.fillRect(0, 0, image.getWidth(), image.getHeight()); // Draws axis lines g.setColor(Color.black);/*from ww w .j a va 2s .c o m*/ g.drawLine(xMargin, IMAGE_HEIGHT - yMargin, IMAGE_WIDTH - xMargin, IMAGE_HEIGHT - yMargin); g.drawLine(xMargin, IMAGE_HEIGHT - yMargin, xMargin, yMargin); // Draws confidence interval if (ic95Option) { g.setColor(Color.lightGray); for (int i = 0; i < upperCI.length - 1; i++) { int[] xPoints = { xMargin + (int) (orderedLog10ExpectedValues[i] * xIncrement), xMargin + (int) (orderedLog10ExpectedValues[i] * xIncrement), xMargin + (int) (orderedLog10ExpectedValues[i + 1] * xIncrement), xMargin + (int) (orderedLog10ExpectedValues[i + 1] * xIncrement) }; int[] yPoints = { IMAGE_HEIGHT - (yMargin + ((int) (upperCI[i] * yIncrement))), IMAGE_HEIGHT - (yMargin + ((int) (lowerCI[i] * yIncrement))), IMAGE_HEIGHT - (yMargin + ((int) (lowerCI[i + 1] * yIncrement))), IMAGE_HEIGHT - (yMargin + ((int) (upperCI[i + 1] * yIncrement))) }; g.fillPolygon(xPoints, yPoints, 4); } } // Draws dots dotRadius = 4; g.setColor(Color.black); for (int i = 0; i < orderedLog10ObservedValues.length; i++) { int xPosition = xMargin + ((int) (orderedLog10ExpectedValues[i] * xIncrement)); int yPosition = IMAGE_HEIGHT - (yMargin + ((int) (orderedLog10ObservedValues[i] * yIncrement))); g.fillOval(xPosition - dotRadius, yPosition - dotRadius, dotRadius * 2, dotRadius * 2); } // --draw y axis scale // ----Calculates interval between labels in y axis int yInterval = 1; int verticalMaxValue = (int) maxObservedLogValue + 1; if (verticalMaxValue > 20) { yInterval = 5; } if (verticalMaxValue > 100) { yInterval = 50; } if (verticalMaxValue > 1000) { yInterval = verticalMaxValue; } g.setColor(Color.BLACK); for (int i = 0; i <= verticalMaxValue; i = i + yInterval) { int yPos = IMAGE_HEIGHT - (yMargin + (int) (((float) i / verticalMaxValue) * (IMAGE_HEIGHT - 2 * yMargin))); g.fillRect(45, yPos, 15, 3); g.setFont(new Font("courier", 1, 30)); String value = String.valueOf(i); if (value.length() == 1) { value = " " + value; } g.drawString(value, 5, yPos + 10); } // --draw x axis scale // ----Calculates interval between labels in x axis int xInterval = 1; int horizontalMaxValue = (int) maxExpectedLogValue + 1; if (horizontalMaxValue > 20) { xInterval = 5; } if (horizontalMaxValue > 100) { xInterval = 50; } if (horizontalMaxValue > 1000) { xInterval = verticalMaxValue; } g.setColor(Color.BLACK); for (int i = 0; i <= horizontalMaxValue; i = i + xInterval) { int xPos = (xMargin + (int) (((float) i / horizontalMaxValue) * (IMAGE_WIDTH - 2 * xMargin))); g.fillRect(xPos, IMAGE_HEIGHT - yMargin, 3, 15); g.setFont(new Font("courier", 1, 30)); String value = String.valueOf(i); if (value.length() == 1) { value = " " + value; } g.drawString(value, xPos - 15, IMAGE_HEIGHT - yMargin + 45); } // Draws identity line g.setColor(Color.RED); int endLineValue = horizontalMaxValue < verticalMaxValue ? horizontalMaxValue : verticalMaxValue; g.drawLine(xMargin, IMAGE_HEIGHT - yMargin, xMargin + ((int) (endLineValue * xIncrement)), IMAGE_HEIGHT - (yMargin + ((int) (endLineValue * yIncrement)))); // -- title g.setColor(Color.blue); g.setFont(new Font("arial", 1, 35)); g.drawString(label, IMAGE_WIDTH / 7, 40); }
From source file:width.java
/** * Paint it./*from w w w. j a va2 s . co m*/ */ public void paint(Graphics g) { Dimension d = getSize(); g.setColor(Color.black); int xoff = d.width / 3; int yoff = d.height / 3; g.drawLine(xoff, 0, xoff, d.height); g.drawLine(2 * xoff, 0, 2 * xoff, d.height); g.drawLine(0, yoff, d.width, yoff); g.drawLine(0, 2 * yoff, d.width, 2 * yoff); int i = 0; for (int r = 0; r < 3; r++) { for (int c = 0; c < 3; c++, i++) { if ((white & (1 << i)) != 0) { g.drawImage(notImage, c * xoff + 1, r * yoff + 1, this); } else if ((black & (1 << i)) != 0) { g.drawImage(crossImage, c * xoff + 1, r * yoff + 1, this); } } } }
From source file:io.github.karols.hocr4j.PageRenderer.java
/** * Renders this page on a blank image.// w w w. java 2 s. c om * The image is filled with the background color. * * @param page page to render * @return rendered image */ @Nonnull public BufferedImage renderOnBlank(@Nonnull Page page) { Bounds pageBounds = page.getBounds().scale(scale); BufferedImage img = new BufferedImage(pageBounds.getRight(), pageBounds.getBottom(), BufferedImage.TYPE_INT_ARGB); Graphics g = img.getGraphics(); g.setColor(backgroundColor); g.fillRect(0, 0, img.getWidth(), img.getHeight()); renderOnTop(page, img); return img; }
From source file:DesktopManagerDemo.java
public void paintEventSquare(Graphics g, int value, int currwidth, int currheight, int cellwidth, int cellheight, Color color) { if (value != 0) { g.setColor(color); g.fillRect(currwidth, currheight, cellwidth, cellheight); g.setColor(Color.green);/*w w w .j ava 2s .co m*/ g.drawString("" + value, currwidth + 5, currheight + 14); } g.setColor(Color.black); g.drawRect(currwidth, currheight, cellwidth, cellheight); }
From source file:Bouncer.java
protected void render() { Graphics g = getGraphics();/*from www.j a va2s .c o m*/ if (g != null) { Dimension d = getSize(); if (checkImage(d)) { Graphics imageGraphics = image.getGraphics(); imageGraphics.setColor(getBackground()); imageGraphics.fillRect(0, 0, d.width, d.height); imageGraphics.setColor(getForeground()); paint(imageGraphics); g.drawImage(image, 0, 0, null); imageGraphics.dispose(); } g.dispose(); } }
From source file:test.mandelbrot.SequentialMandelbrotApp.java
@Override public synchronized void paint(Graphics g) { if (done) {//from www . j av a 2 s. co m g.drawImage(offscreen, 0, 0, this); this.setTitle("Done"); } else { g.drawImage(offscreen, 0, 0, this); g.setColor(Color.white); g.drawRect(WIDTH / 4, 10, WIDTH / 2, 5); g.fillRect(WIDTH / 4, 11, (progress * (WIDTH / 2)) / HEIGHT, 4); } }
From source file:Main.java
public void paint(Graphics g, Shape a) { super.paint(g, a); Color c = (Color) getElement().getAttributes().getAttribute("Underline-Color"); if (c != null) { int y = a.getBounds().y + (int) getGlyphPainter().getAscent(this); int x1 = a.getBounds().x; int x2 = a.getBounds().width + x1; g.setColor(c); g.drawLine(x1, y, x2, y);// w w w . j a va 2 s . co m } }
From source file:CalIcon.java
/** paintIcon: draw the calendar page. */ public void paintIcon(Component c, Graphics g, int x, int y) { // Allow clock to get painted (voodoo magic) if (showTime) super.paint(g); // Outline it. g.setColor(Color.black); g.draw3DRect(x, y, d.width - 2, d.height - 2, true); // Show the date: First, a white page with a drop shadow. g.setColor(Color.gray);//from w w w. j a va2 s .c o m g.fillRect(x + RBX + 3, y + RBY + 3, RBW, RBH); g.setColor(Color.white); g.fillRect(x + RBX, y + RBY, RBW, RBH); // g.setColor(getForeground()); g.setColor(Color.black); String s = days[myCal.get(Calendar.DAY_OF_WEEK) - 1]; g.setFont(dayNameFont); int w = dayNameFM.stringWidth(s); g.drawString(s, x + RBX + ((RBW - w) / 2), y + RBY + 10); s = Integer.toString(myCal.get(Calendar.DAY_OF_MONTH)); g.setFont(dayNumbFont); w = dayNumbFM.stringWidth(s); g.drawString(s, x + RBX + ((RBW - w) / 2), y + RBY + 25); s = mons[myCal.get(Calendar.MONTH)]; g.setFont(monNameFont); w = monNameFM.stringWidth(s); g.drawString(s, x + RBX + ((RBW - w) / 2), y + RBY + 35); }