List of usage examples for java.awt Graphics setColor
public abstract void setColor(Color c);
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; RenderingHints rh = g2.getRenderingHints(); rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHints(rh);/* w w w. ja v a 2 s .co m*/ int x = 40, y = 40; g.setColor(Color.red); g.fillOval(x, y, 50, 50); Composite old = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR)); g.setColor(Color.green); g.fillOval(x + 30, y + 30, 30, 30); g2.setComposite(old); g.setColor(Color.black); g.drawString("AlphaComposite.CLEAR", x, y + 80); }
From source file:com.krawler.esp.handlers.FileUploadHandler.java
private BufferedImage toBufferedImage(Image image, int type) { image = new ImageIcon(image).getImage(); BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), type); Graphics g = bufferedImage.createGraphics(); if (type == BufferedImage.TYPE_INT_RGB) { g.setColor(Color.white); g.fillRect(0, 0, image.getWidth(null), image.getHeight(null)); }//from w ww .j a va 2s . co m g.drawImage(image, 0, 0, null); g.dispose(); return bufferedImage; }
From source file:com.cburch.logisim.circuit.appear.AppearancePort.java
@Override public void paint(Graphics g, HandleGesture gesture) { Location location = getLocation(); int x = location.getX(); int y = location.getY(); g.setColor(COLOR); if (isInput()) { int r = INPUT_RADIUS; g.drawRect(x - r, y - r, 2 * r, 2 * r); } else {/* www.ja v a 2 s .co m*/ int r = OUTPUT_RADIUS; g.drawOval(x - r, y - r, 2 * r, 2 * r); } g.fillOval(x - MINOR_RADIUS, y - MINOR_RADIUS, 2 * MINOR_RADIUS, 2 * MINOR_RADIUS); }
From source file:MyCheckBoxUI.java
public void paint(Graphics g, JComponent c) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); Dimension d = b.getSize();//from www . jav a2s . c o m g.setFont(c.getFont()); FontMetrics fm = g.getFontMetrics(); g.setColor(Color.white); g.drawString("Am I a check box", 10, 10); }
From source file:Main.java
private void myPaint(Component comp, Graphics g) { int x = comp.getX(); int y = comp.getY(); g.translate(x, y);/* w w w . ja va 2 s .c om*/ cursor.translate(-x, -y); if (comp.contains(cursor)) { String cls_name = comp.getClass().getName(); g.setColor(Color.black); g.drawString(cls_name, 0, 10); } if (comp instanceof Container) { Container cont = (Container) comp; for (int i = 0; i < cont.getComponentCount(); i++) { Component child = cont.getComponent(i); myPaint(child, g); } } cursor.translate(x, y); g.translate(-x, -y); }
From source file:ColorDifference.java
/** * Displays our component with the animating colors of the areas on the left * and right, separated by an area of white in the middle *//*from w w w . j a v a2 s . com*/ @Override protected void paintComponent(Graphics g) { int fadeX = 0; int blankX = getWidth() / 3; int bigRectW = getWidth() / 3; // Fill left-side rectangle with current animating color g.setColor(largeRectColors[colorIndex]); g.fillRect(0, 0, bigRectW, getHeight()); // Fill middle area with white g.setColor(Color.WHITE); g.fillRect(bigRectW, 0, bigRectW, getHeight()); // Fill right-side rectangle with black, with a white square // in the middle int bigRectX = 2 * bigRectW; int smallRectW = 4; int smallRectH = 4; int smallRectX = bigRectX + (bigRectW / 2) - (smallRectW / 2); int smallRectY = (getHeight() / 2) - (smallRectH / 2); g.setColor(Color.BLACK); g.fillRect(2 * getWidth() / 3, 0, getWidth() / 3, getHeight()); g.setColor(smallRectColors[colorIndex]); g.fillRect(smallRectX, smallRectY, smallRectW, smallRectH); }
From source file:layout.BLDComponent.java
public void paint(Graphics g) { int width = getWidth(); int height = getHeight(); float alignmentX = getAlignmentX(); g.setColor(normalHue); g.fill3DRect(0, 0, width, height, true); /* Draw a vertical white line at the alignment point.*/ // XXX: This code is probably not the best. g.setColor(Color.white);/*from ww w .ja v a 2 s . co m*/ int x = (int) (alignmentX * (float) width) - 1; g.drawLine(x, 0, x, height - 1); /* Say what the alignment point is. */ g.setColor(Color.black); g.drawString(Float.toString(alignmentX), 3, height - 3); if (printSize) { System.out.println("BLDComponent " + name + ": size is " + width + "x" + height + "; preferred size is " + getPreferredSize().width + "x" + getPreferredSize().height); } }
From source file:MainClass.java
public void paint(Graphics g) { int n = 3;/*from ww w . ja v a2s . com*/ int xdata[] = new int[n]; int ydata[] = new int[n]; xdata[0] = 50; ydata[0] = 150; xdata[1] = 200; ydata[1] = 50; xdata[2] = 350; ydata[2] = 150; int rgb = Color.HSBtoRGB(1.0f, 1.0f, 1.0f); g.setColor(new Color(rgb)); g.fillPolygon(xdata, ydata, n); }
From source file:org.b3log.symphony.service.AvatarQueryService.java
/** * Creates a avatar image with the specified hash string and size. * * <p>/*w w w . j ava2 s . co m*/ * Refers to: https://github.com/superhj1987/awesome-identicon * </p> * * @param hash the specified hash string * @param size the specified size * @return buffered image */ public BufferedImage createAvatar(final String hash, final int size) { final boolean[][] array = new boolean[6][5]; for (int i = 0; i < 6; i++) { for (int j = 0; j < 5; j++) { array[i][j] = false; } } for (int i = 0; i < hash.length(); i += 2) { final int s = i / 2; final boolean v = Math.random() > 0.5; if (s % 3 == 0) { array[s / 3][0] = v; array[s / 3][4] = v; } else if (s % 3 == 1) { array[s / 3][1] = v; array[s / 3][3] = v; } else { array[s / 3][2] = v; } } final int ratio = Math.round(size / 5); final BufferedImage ret = new BufferedImage(ratio * 5, ratio * 5, BufferedImage.TYPE_3BYTE_BGR); final Graphics graphics = ret.getGraphics(); graphics.setColor(new Color(Integer.parseInt(String.valueOf(hash.charAt(0)), 16) * 16, Integer.parseInt(String.valueOf(hash.charAt(1)), 16) * 16, Integer.parseInt(String.valueOf(hash.charAt(2)), 16) * 16)); graphics.fillRect(0, 0, ret.getWidth(), ret.getHeight()); graphics.setColor(new Color(Integer.parseInt(String.valueOf(hash.charAt(hash.length() - 1)), 16) * 16, Integer.parseInt(String.valueOf(hash.charAt(hash.length() - 2)), 16) * 16, Integer.parseInt(String.valueOf(hash.charAt(hash.length() - 3)), 16) * 16)); for (int i = 0; i < 6; i++) { for (int j = 0; j < 5; j++) { if (array[i][j]) { graphics.fillRect(j * ratio, i * ratio, ratio, ratio); } } } return ret; }
From source file:jurls.core.utils.MatrixImage.java
@Override public void paint(Graphics g) { if (image == null) { g.setColor(Color.GRAY); g.fillRect(0, 0, getWidth(), getHeight()); } else/*from w w w .j a v a 2s .c om*/ g.drawImage(image, 0, 0, getWidth(), getHeight(), null); }