Example usage for java.awt Graphics setColor

List of usage examples for java.awt Graphics setColor

Introduction

In this page you can find the example usage for java.awt Graphics setColor.

Prototype

public abstract void setColor(Color c);

Source Link

Document

Sets this graphics context's current color to the specified color.

Usage

From source file:SimpleBorder.java

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {

    Insets insets = getBorderInsets(c);
    if (color != null)
        g.setColor(color);

    g.fill3DRect(0, 0, width - insets.right, insets.top, true);

    g.fill3DRect(0, insets.top, insets.left, height - insets.top, true);
    g.fill3DRect(insets.left, height - insets.bottom, width - insets.left, insets.bottom, true);
    g.fill3DRect(width - insets.right, 0, insets.right, height - insets.bottom, true);
}

From source file:Clock.java

private void drawStructure(Graphics g) {
    g.setFont(new Font("TimesRoman", Font.PLAIN, 14));
    g.setColor(Color.blue);
    g.drawOval(xcenter - 50, ycenter - 50, 100, 100);
    g.setColor(Color.darkGray);//from   w w w. j  a v a  2 s.  c  o  m
    g.drawString("9", xcenter - 45, ycenter + 3);
    g.drawString("3", xcenter + 40, ycenter + 3);
    g.drawString("12", xcenter - 5, ycenter - 37);
    g.drawString("6", xcenter - 3, ycenter + 45);

}

From source file:FlexBorder.java

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    g.setColor(color);

    switch (type) {
    case TOP_LINE:
        g.drawLine(x, y, x + width - 1, y);
        break;/*w  w  w.ja  va2s .c  o m*/

    case BOTTOM_LINE:
        g.drawLine(x, y + height - 1, x + width - 1, y + height - 1);
        break;

    case RECT:
        g.drawRect(x, y, width - 1, height - 1);
        break;
    }
}

From source file:com.lixiaocong.service.ImageCodeService.java

public BufferedImage getImage(HttpSession session) {
    //background//from   w w  w .  j  a  v a  2  s .co  m
    BufferedImage bi = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
    Graphics graphics = bi.getGraphics();
    graphics.setColor(randomColor());
    graphics.fillRect(0, 0, WIDTH, HEIGHT);

    //content
    StringBuilder sb = new StringBuilder();
    int len = ch.length;
    Random random = new Random();
    for (int i = 0; i < 4; i++) {
        int index = random.nextInt(len);
        graphics.setColor(randomColor());
        graphics.setFont(new Font(null, Font.BOLD + Font.ITALIC, 30));
        graphics.drawString(ch[index] + "", i * 15 + 5, 25);
        sb.append(ch[index]);
    }
    session.setAttribute("imagecode", sb.toString());

    //lines
    for (int i = 0; i < 4; i++) {
        graphics.setColor(randomColor());
        graphics.drawLine(random.nextInt(WIDTH), random.nextInt(HEIGHT), random.nextInt(WIDTH),
                random.nextInt(HEIGHT));
    }

    return bi;
}

From source file:mainDraw.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawRect(x, y, 50, 50);// w  w  w. java  2  s .  c o  m
    g.fillRect(x, y, 50, 50);
    g.setColor(Color.BLACK);
}

From source file:components.ArrowIcon.java

public void paintIcon(Component c, Graphics g, int x, int y) {
    if (c.isEnabled()) {
        g.setColor(c.getForeground());
    } else {/*from   w w w  .  j a v  a  2 s.  c  om*/
        g.setColor(Color.gray);
    }

    g.translate(x, y);
    g.fillPolygon(xPoints, yPoints, xPoints.length);
    g.translate(-x, -y); //Restore graphics object
}

From source file:org.chos.transaction.passport.controller.CaptchaController.java

@RequestMapping(value = "/captcha")
public void captcha(HttpServletRequest request, HttpServletResponse response) throws IOException {
    BufferedImage bi = new BufferedImage(40, 18, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();
    String c = generate();// ww  w  . j av  a2 s  . co  m
    g.setColor(Color.white);
    g.fillRect(1, 1, 38, 16);

    g.setColor(generateColor());
    g.drawString(c, 4, 13);
    response.setContentType("image/jpeg");
    ServletOutputStream os = response.getOutputStream();
    //      os.write(b)
    //      ImageIO.createImageOutputStream(os);
    ImageIO.write(bi, "jpg", os);
    os.flush();
    os.close();
    request.getSession().setAttribute("captcha", c);
}

From source file:ColorSource.java

public void paintComponent(Graphics g) {
    g.setColor(color);
    Dimension s = this.getSize();
    Insets i = this.getInsets();
    g.fillRect(i.left, i.top, s.width - i.left - i.right, s.height - i.top - i.bottom);
}

From source file:com.foudroyantfactotum.mod.fousarchive.midi.generation.MidiImageGeneration.java

public ImmutablePair<String, BufferedImage> buildImage() throws InterruptedException, ExecutionException {
    final Future<String> name = pool.submit(new LineProcessor(imgX));
    final BufferedImage mdbf = new BufferedImage(imgX, imgY, BufferedImage.TYPE_BYTE_GRAY);
    final Graphics g = mdbf.getGraphics();

    g.setColor(Color.BLACK);
    g.fillRect(0, 0, imgX, imgY);//ww  w  .  j av  a 2s .  c o  m
    g.setColor(Color.WHITE);

    for (Line l = lines.take(); l != TERMINATE; l = lines.take()) {
        g.drawLine(l.note, (int) Math.round(l.tickStart * imgY), l.note, (int) Math.round(l.tickEnd * imgY));
    }

    pool.shutdown();

    g.dispose();

    return ImmutablePair.of(name.get(), mdbf);
}

From source file:BezLab.java

public void paint(Graphics g) {
    for (int i = 0; i < 4; i++) {
        if (i == 0 || i == 3)
            g.setColor(Color.blue);
        else//from   w ww.j a  va  2  s.c  om
            g.setColor(Color.cyan);
        g.fillOval(xs[i] - 6, ys[i] - 6, 12, 12);
    }
    Graphics2D g2d = (Graphics2D) g;
    g2d.setColor(Color.black);
    GeneralPath path = new GeneralPath();
    path.moveTo(xs[0], ys[0]);
    path.curveTo(xs[1], ys[1], xs[2], ys[2], xs[3], ys[3]);
    g2d.draw(path);
}