List of usage examples for java.awt Graphics setColor
public abstract void setColor(Color c);
From source file:DebugFrame.java
/** * Clears the back buffer//from w w w .j av a 2 s . c o m */ public void clear() { Graphics g = panel.buff.getGraphics(); g.setColor(Color.white); g.fillRect(0, 0, panel.getWidth(), panel.getHeight()); }
From source file:JToolbarSeparator.java
protected void paintComponent(Graphics g) { super.paintComponent(g); Dimension size = getSize();/*from w w w. j a va 2 s .c o m*/ int pos = size.width / 2; g.setColor(Color.gray); g.drawLine(pos, 3, pos, size.height - 5); g.drawLine(pos, 2, pos + 1, 2); g.setColor(Color.white); g.drawLine(pos + 1, 3, pos + 1, size.height - 5); g.drawLine(pos, size.height - 4, pos + 1, size.height - 4); }
From source file:net.d53dev.dslfy.web.service.GifService.java
public BufferedImage convertRGBAToGIF(BufferedImage src, int transColor) { BufferedImage dst = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_INDEXED); Graphics g = dst.getGraphics(); g.setColor(new Color(transColor)); g.fillRect(0, 0, dst.getWidth(), dst.getHeight()); {// ww w. j a v a 2s .c o m IndexColorModel indexedModel = (IndexColorModel) dst.getColorModel(); WritableRaster raster = dst.getRaster(); int sample = raster.getSample(0, 0, 0); int size = indexedModel.getMapSize(); byte[] rr = new byte[size]; byte[] gg = new byte[size]; byte[] bb = new byte[size]; indexedModel.getReds(rr); indexedModel.getGreens(gg); indexedModel.getBlues(bb); IndexColorModel newModel = new IndexColorModel(8, size, rr, gg, bb, sample); dst = new BufferedImage(newModel, raster, dst.isAlphaPremultiplied(), null); } dst.createGraphics().drawImage(src, 0, 0, null); return dst; }
From source file:ColorGradient.java
/** Draw the applet. The interesting code is in fillGradient() below */ public void paint(Graphics g) { fillGradient(this, g, startColor, endColor); // display the gradient g.setFont(bigFont); // set a font g.setColor(new Color(100, 100, 200)); // light blue g.drawString("Colors!", 100, 100); // draw something interesting }
From source file:com.synnex.saas.platform.core.servlet.CaptchaServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {// w w w . j a v a 2 s . c o m int width = 50; int height = 18; String captchaCode = RandomStringUtils.random(4, true, true); HttpSession session = request.getSession(true); session.setAttribute("captchaCode", captchaCode); response.setContentType("images/jpeg"); response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); ServletOutputStream out = response.getOutputStream(); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); g.setColor(getRandColor(200, 250)); g.fillRect(0, 0, width, height); Font mFont = new Font("Times New Roman", Font.BOLD, 18); g.setFont(mFont); g.setColor(getRandColor(160, 200)); Random random = new Random(); for (int i = 0; i < 155; i++) { int x2 = random.nextInt(width); int y2 = random.nextInt(height); int x3 = random.nextInt(12); int y3 = random.nextInt(12); g.drawLine(x2, y2, x2 + x3, y2 + y3); } g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110))); g.drawString(captchaCode, 2, 16); g.dispose(); ImageIO.write((BufferedImage) image, "JPEG", out); out.close(); } catch (Exception e) { logger.error("Generate captcha failed.", e); } }
From source file:MyCanvas.java
public void paintComponent(Graphics g) { super.paintComponent(g); // draw entire component white g.setColor(Color.white); g.fillRect(0, 0, getWidth(), getHeight()); // yellow circle g.setColor(Color.yellow);/*from ww w .j a v a 2 s. c o m*/ g.fillOval(0, 0, 240, 240); // magenta circle g.setColor(Color.magenta); g.fillOval(160, 160, 240, 240); // paint the icon below blue sqaure int w = java2sLogo.getIconWidth(); int h = java2sLogo.getIconHeight(); java2sLogo.paintIcon(this, g, 280 - (w / 2), 120 - (h / 2)); // paint the icon below red sqaure java2sLogo.paintIcon(this, g, 120 - (w / 2), 280 - (h / 2)); // transparent red square g.setColor(m_tRed); g.fillRect(60, 220, 120, 120); // transparent green circle g.setColor(m_tGreen); g.fillOval(140, 140, 120, 120); // transparent blue square g.setColor(m_tBlue); g.fillRect(220, 60, 120, 120); g.setColor(Color.black); g.setFont(monoFont); FontMetrics fm = g.getFontMetrics(); w = fm.stringWidth("Java Source"); h = fm.getAscent(); g.drawString("Java Source", 120 - (w / 2), 120 + (h / 4)); g.setFont(sanSerifFont); fm = g.getFontMetrics(); w = fm.stringWidth("and"); h = fm.getAscent(); g.drawString("and", 200 - (w / 2), 200 + (h / 4)); g.setFont(serifFont); fm = g.getFontMetrics(); w = fm.stringWidth("Support."); h = fm.getAscent(); g.drawString("Support.", 280 - (w / 2), 280 + (h / 4)); }
From source file:Main.java
public void paint(Graphics g) { g.fillRect(0, 0, 20, 20);//from w w w. ja va 2 s . c om Graphics2D g2 = (Graphics2D) g; g2.shear(5.3, 5.4); g2.rotate(30.0 * Math.PI / 180.0); g2.scale(2.0, 2.0); g.setColor(Color.red); g.fillRect(0, 0, 20, 20); }
From source file:FillRectPanel.java
public void paintComponent(Graphics g) { super.paintComponent(g); g.drawRect(10, 10, 80, 30);/*from w w w .j a va2s .c o m*/ g.drawRoundRect(100, 10, 80, 30, 15, 15); g.drawOval(10, 100, 80, 30); g.setColor(Color.red); g.fillRect(10, 10, 80, 30); g.fillRoundRect(100, 10, 80, 30, 15, 15); int thickness = 4; g.fill3DRect(200, 10, 80, 30, true); for (int i = 1; i <= thickness; i++) g.draw3DRect(200 - i, 10 - i, 80 + 2 * i - 1, 30 + 2 * i - 1, true); g.fill3DRect(200, 50, 80, 30, false); for (int i = 1; i <= thickness; i++) g.draw3DRect(200 - i, 50 - i, 80 + 2 * i - 1, 30 + 2 * i - 1, true); g.fillOval(10, 100, 80, 30); }
From source file:test.buddhabrot.BuddhabrotApp.java
public BuddhabrotApp(final GridNode node) throws HeadlessException { super();//from www .j a v a 2 s . co m setSize(WIDTH, HEIGHT); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { try { if (future != null) { if (!future.isJobFinished()) { log.info("Cancelling Job... wait"); setTitle("Cancelling Job - WAIT"); if (!future.cancel()) { log.warn("Cancel Failed"); } } } node.shutdown(); // Give time to send termination message try { Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } } catch (Exception ex) { ex.printStackTrace(); } System.exit(0); } }); setVisible(true); // create off-screen buffer Graphics g = image.getGraphics(); g.setColor(Color.black); g.fillRect(0, 0, WIDTH, HEIGHT); repaint(); }
From source file:com.codenvy.corp.MainPage.java
private void addText(File file, String burnDownInfo) throws IOException { BufferedImage image = ImageIO.read(file); Graphics g = image.getGraphics(); g.setColor(Color.RED); g.setFont(g.getFont().deriveFont(30f)); g.drawString(burnDownInfo, 550, 45); g.dispose();//from www . ja v a 2 s.c o m ImageIO.write(image, "png", file); }