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

public void paint(Graphics g) {
    g.setColor(getForeground());
    g.drawString("Parameter", 10, 10);

}

From source file:MainClass.java

public void paint(Graphics g) {
    int deltax = 260 / colors.length;
    for (int i = 0; i < colors.length; i++) {
        g.setColor(colors[i]);
        g.fillRect(i * deltax, 0, (i + 1) * deltax, 260);
    }/*from  w  w  w  .  ja v a  2s  .c o m*/

}

From source file:MouseTest.java

public void paint(Graphics g) {
    super.paint(g);
    g.setColor(color);
    g.drawLine(startX, startY, endX, endY);
}

From source file:BufferedAnimate.java

public void paint(Graphics g) {
    if ((oldSize == null) || (oldSize != getSize())) {
        oldSize = getSize();/*www . j  av  a  2 s. c o  m*/
        buffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
    }
    if (insets == null) {
        insets = getInsets();
    }
    // Calculate each time in case of resize
    int x = insets.left;
    int y = insets.top;
    int width = getWidth() - insets.left - insets.right;
    int height = getHeight() - insets.top - insets.bottom;
    int start = 0;
    int steps = colors.length;
    int stepSize = 360 / steps;
    synchronized (colors) {
        Graphics bufferG = buffer.getGraphics();
        bufferG.setColor(Color.WHITE);
        bufferG.fillRect(x, y, width, height);
        for (int i = 0; i < steps; i++) {
            bufferG.setColor(colors[i]);
            bufferG.fillArc(x, y, width, height, start, stepSize);
            start += stepSize;
        }
    }
    g.drawImage(buffer, 0, 0, this);
}

From source file:Main.java

License:asdf

public void paint(Graphics g, JComponent c) {
    FontMetrics metrics = c.getFontMetrics(g.getFont());
    g.setColor(c.getForeground());
    g.drawString(((JToolTip) c).getTipText(), 1, 1);
    g.drawImage(new ImageIcon("yourImage").getImage(), 1, metrics.getHeight(), c);
}

From source file:SaveYourDrawingToFile.java

public void paint(Graphics g) {
    g.setColor(Color.white);
    g.fillRect(0, 0, getSize().width, getSize().height);

    g.setColor(Color.black);//from  www.  j a v a 2 s .c  o m
    int i = 0;
    while (i < displayList.size()) {
        Point p0 = (Point) (displayList.get(i++));
        Point p1 = (Point) (displayList.get(i++));
        int x = Math.min(p0.x, p1.x);
        int y = Math.min(p0.y, p1.y);
        int w = Math.abs(p0.x - p1.x);
        int h = Math.abs(p0.y - p1.y);
        g.drawRect(x, y, w, h);
    }
}

From source file:Main.java

public void paint(Graphics g) {
    g.setColor(isActive ? ACTIVE_COLOR : INACTIVE_COLOR);
    g.drawPolygon(polygon);
}

From source file:BouncingCircle.java

/** This method simply draws the circle at its current position */
public void paint(Graphics g) {
    g.setColor(Color.red);
    g.fillOval(x - r, y - r, r * 2, r * 2);
}

From source file:PlainColorIcon.java

public void paintIcon(Component c, Graphics g, int x, int y) {
    Color old_color = g.getColor();
    g.setColor(color);
    g.fillRect(x, y, 10, 10);/* ww w .  jav  a 2s. c om*/
    g.setColor(old_color);
}

From source file:components.Corner.java

protected void paintComponent(Graphics g) {
    // Fill me with dirty brown/orange.
    g.setColor(new Color(230, 163, 4));
    g.fillRect(0, 0, getWidth(), getHeight());
}