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:RightSideBorder.java

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Color oldColor = g.getColor();
    int i;/*from ww w  . j  a v  a 2  s  . c  o  m*/

    g.setColor(lineColor);
    for (i = 0; i < thickness; i++) {
        g.drawLine(x + width - i - 1, y, x + width - i - 1, y + height);
    }
    g.setColor(oldColor);
}

From source file:org.pmedv.core.app.PostApplicationStartupConfigurer.java

public PostApplicationStartupConfigurer(String fileLocation) {
    this.fileLocation = fileLocation;
    log.info(AppContext.getName() + " initialized.");
    BufferedImage image = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
    Graphics g = image.getGraphics();
    g.setColor(Color.BLACK);
    g.fillRect(0, 0, 16, 16);/* w  ww.jav  a 2 s  . c om*/
    AppContext.getContext().getBean(ApplicationWindow.class).getStatusLabel().setIcon(new ImageIcon(image));
}

From source file:ColorsBeanInfo.java

public void paint(Graphics g) {
        Dimension d = getSize();//  www.  ja v a  2s . c  om
        int h = d.height;
        int w = d.width;
        g.setColor(color);
        if (rectangular) {
            g.fillRect(0, 0, w - 1, h - 1);
        } else {
            g.fillOval(0, 0, w - 1, h - 1);
        }
    }

From source file:cpcc.core.utils.PngImageStreamResponseTest.java

@Test
public void shouldConvertBufferedImage() throws IOException {
    BufferedImage image = new BufferedImage(2, 2, BufferedImage.TYPE_INT_ARGB);
    Graphics gr = image.getGraphics();
    gr.setColor(Color.GREEN);
    gr.drawLine(0, 0, 1, 1);/*from  w  w  w  . ja  v  a 2 s. co  m*/
    gr.setColor(Color.BLACK);
    gr.drawLine(1, 1, 0, 0);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(image, "PNG", baos);
    byte[] expected = baos.toByteArray();

    StreamResponse response = PngImageStreamResponse.convertImageToStreamResponse(image);

    assertThat(response.getStream()).isNotNull();
    byte[] actual = IOUtils.toByteArray(response.getStream());

    assertThat(actual).isEqualTo(expected);
}

From source file:com.aistor.common.servlet.ValidateCodeServlet.java

private void createBackground(Graphics g) {
    // //from   w ww . j a  va  2  s  .  c om
    g.setColor(getRandColor(220, 250));
    g.fillRect(0, 0, w, h);
    // ?
    for (int i = 0; i < 10; i++) {
        g.setColor(getRandColor(40, 150));
        Random random = new Random();
        int x = random.nextInt(w);
        int y = random.nextInt(h);
        int x1 = random.nextInt(w);
        int y1 = random.nextInt(h);
        g.drawLine(x, y, x1, y1);
    }
}

From source file:apm.common.servlet.ValidateCodeServlet.java

private void createBackground(Graphics g) {
    // /* w ww  . ja v  a  2s. c om*/
    g.setColor(getRandColor(220, 250));
    g.fillRect(0, 0, w, h);
    // ?
    for (int i = 0; i < 8; i++) {
        g.setColor(getRandColor(40, 150));
        Random random = new Random();
        int x = random.nextInt(w);
        int y = random.nextInt(h);
        int x1 = random.nextInt(w);
        int y1 = random.nextInt(h);
        g.drawLine(x, y, x1, y1);
    }
}

From source file:Main.java

public void paintComponent(Graphics g) {
    ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(Color.black);
    g.drawString(month.format(date), 34, 36);
    g.setColor(Color.white);/*from  www. ja v a  2  s .  c  o m*/
    g.drawString(year.format(date), 235, 36);

    Calendar today = Calendar.getInstance();
    today.setTime(date);
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.set(Calendar.DATE, 1);
    cal.add(Calendar.DATE, -cal.get(Calendar.DAY_OF_WEEK) + 1);
    for (int week = 0; week < 6; week++) {
        for (int d = 0; d < 7; d++) {
            Color col = Color.black;
            g.drawString(day.format(cal.getTime()), d * 30 + 46 + 4, week * 29 + 81 + 20);
            cal.add(Calendar.DATE, +1);
        }
    }
}

From source file:RectangleBorder.java

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Color oldColor = g.getColor();

    g.setColor(lineColor);
    // top/*from w  w  w.ja v  a2s .c  om*/
    for (int i = 0; i < thickness.top; i++) {
        g.drawLine(x, y + i, x + width, y + i);
    }
    // bottom
    for (int i = 0; i < thickness.bottom; i++) {
        g.drawLine(x, y + height - i - 1, x + width, y + height - i - 1);
    }
    // right
    for (int i = 0; i < thickness.right; i++) {
        g.drawLine(x + width - i - 1, y, x + width - i - 1, y + height);
    }
    // left
    for (int i = 0; i < thickness.left; i++) {
        g.drawLine(x + i, y, x + i, y + height);
    }
    g.setColor(oldColor);
}

From source file:TextBox3D.java

public synchronized void paint(Graphics g) {
    FontMetrics fm = g.getFontMetrics();
    Dimension size = getSize();/*  w ww  .  j  a va2 s.  c  o  m*/
    int x = (size.width - fm.stringWidth(text)) / 2;
    int y = (size.height - fm.getHeight()) / 2;
    g.setColor(SystemColor.control);
    g.fillRect(0, 0, size.width, size.height);
    g.setColor(SystemColor.controlShadow);
    g.drawLine(0, 0, 0, size.height - 1);
    g.drawLine(0, 0, size.width - 1, 0);
    g.setColor(SystemColor.controlDkShadow);
    g.drawLine(0, size.height - 1, size.width - 1, size.height - 1);
    g.drawLine(size.width - 1, 0, size.width - 1, size.height - 1);
    g.setColor(SystemColor.controlText);
    g.drawString(text, x, y);
}

From source file:Layers.java

public void paint(Graphics g) {
    Color c1 = new Color(200, 100, 100, 50); // r, g, b, a
    Color c2 = new Color(100, 200, 000, 128);
    Color c3 = new Color(100, 200, 000, 255);
    g.setColor(c1);
    g.fillRect(0, 0, width / 2, height / 2);
    g.setColor(c2);/*  w  w w.  j a v a 2  s .  co m*/
    g.fillRect(width / 4, height / 4, width / 2, height / 2);
    g.setColor(c3);
    g.fillRect(width / 3, height / 3, width / 4, height / 4);
}