Example usage for java.awt Color gray

List of usage examples for java.awt Color gray

Introduction

In this page you can find the example usage for java.awt Color gray.

Prototype

Color gray

To view the source code for java.awt Color gray.

Click Source Link

Document

The color gray.

Usage

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2D;//from   w  ww  .  j  a  v  a 2  s. c  om
    g2D = (Graphics2D) g;

    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    FontRenderContext frc = g2D.getFontRenderContext();
    Font font1 = new Font("Courier", Font.BOLD, 24);
    String str1 = new String("Java");
    TextLayout tl = new TextLayout(str1, font1, frc);
    g2D.setColor(Color.gray);
    tl.draw(g2D, 50, 150);
}

From source file:LineDemo2D.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.gray);
    int x = 5;/* www  . j av  a2s.  c  o  m*/
    int y = 7;

    g2.draw(new Line2D.Double(x, y, 200, 200));
    g2.drawString("Line2D", x, 250);

}

From source file:Main.java

public void paint(Graphics g) {

    int fontSize = 20;

    g.setFont(new Font("TimesRoman", Font.PLAIN, fontSize));

    FontMetrics fm = g.getFontMetrics();

    String s = "www.java2s.com";

    int stringWidth = fm.stringWidth(s);

    int w = 200;//  w w w  .ja  v  a2  s.c o m
    int h = 200;

    int x = (w - stringWidth) / 2;
    int baseline = fm.getMaxAscent() + (h - (fm.getAscent() + fm.getMaxDecent())) / 2;
    int ascent = fm.getMaxAscent();
    int descent = fm.getMaxDecent();
    int fontHeight = fm.getMaxAscent() + fm.getMaxDecent();

    g.setColor(Color.white);
    g.fillRect(x, baseline - ascent, stringWidth, fontHeight);

    g.setColor(Color.gray);
    g.drawLine(x, baseline, x + stringWidth, baseline);

    g.setColor(Color.red);
    g.drawLine(x, baseline + descent, x + stringWidth, baseline + descent);

    g.setColor(Color.blue);
    g.drawLine(x, baseline - ascent, x + stringWidth, baseline - ascent);
    g.setColor(Color.black);
    g.drawString(s, x, baseline);

}

From source file:Main.java

public ChessButton(int i) {
    super(i / N + "," + i % N);
    this.setOpaque(true);
    this.setBorderPainted(false);
    if ((i / N + i % N) % 2 == 1) {
        this.setBackground(Color.gray);
    }/*from   www  .  j a va  2  s. co m*/
}

From source file:FilledRectangleDemo2D.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.gray);
    int x = 5;//  ww w. j  a  v  a 2  s .  com
    int y = 7;

    g2.setPaint(Color.red);
    g2.fill(new Rectangle2D.Double(x, y, 200, 200));
    g2.setPaint(Color.black);
    g2.drawString("Filled Rectangle2D", x, 250);
}

From source file:GradientPaintDemo2D.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.gray);
    int x = 5;/*from   w  ww  .j av a 2  s.c  o m*/
    int y = 7;
    // fill RoundRectangle2D.Double
    GradientPaint redtowhite = new GradientPaint(x, y, Color.red, 200, y, Color.blue);
    g2.setPaint(redtowhite);
    g2.fill(new RoundRectangle2D.Double(x, y, 200, 200, 10, 10));
    g2.setPaint(Color.black);
    g2.drawString("Filled RoundRectangle2D", x, 250);

}

From source file:GeneralPathDemo2D.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.gray);
    int x = 5;//ww w .  j  a va 2  s .c om
    int y = 7;

    // draw GeneralPath (polygon)
    int xPoints[] = { x, 200, x, 200 };
    int yPoints[] = { y, 200, 200, y };
    GeneralPath polygon = new GeneralPath(GeneralPath.WIND_EVEN_ODD, xPoints.length);
    polygon.moveTo(xPoints[0], yPoints[0]);
    for (int index = 1; index < xPoints.length; index++) {
        polygon.lineTo(xPoints[index], yPoints[index]);
    }
    polygon.closePath();

    g2.draw(polygon);
    g2.drawString("GeneralPath", x, 250);

}

From source file:GeneralPathOpenDemo2D.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.gray);
    int x = 5;/*w  w  w.  j av  a  2s.c  o  m*/
    int y = 7;

    // draw GeneralPath (polyline)

    int xPoints[] = { x, 200, x, 200 };
    int yPoints[] = { y, 200, 200, y };
    GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, xPoints.length);
    polyline.moveTo(xPoints[0], yPoints[0]);
    for (int index = 1; index < xPoints.length; index++) {
        polyline.lineTo(xPoints[index], yPoints[index]);
    }

    g2.draw(polyline);
    g2.drawString("GeneralPath (open)", x, 250);
}

From source file:MainClass.java

public void paint(Graphics g) {
    int fontSize = 20;

    g.setFont(new Font("TimesRoman", Font.PLAIN, fontSize));

    FontMetrics fm = g.getFontMetrics();

    String s = "www.java2s.com";

    int stringWidth = fm.stringWidth(s);

    int w = 200;/*from   w  w  w  . j  a  v a  2s.  c om*/
    int h = 200;

    int x = (w - stringWidth) / 2;
    int baseline = fm.getMaxAscent() + (h - (fm.getAscent() + fm.getMaxDecent())) / 2;
    int ascent = fm.getMaxAscent();
    int descent = fm.getMaxDecent();
    int fontHeight = fm.getMaxAscent() + fm.getMaxDecent();

    g.setColor(Color.white);
    g.fillRect(x, baseline - ascent, stringWidth, fontHeight);

    g.setColor(Color.gray);
    g.drawLine(x, baseline, x + stringWidth, baseline);

    g.setColor(Color.red);
    g.drawLine(x, baseline + descent, x + stringWidth, baseline + descent);

    g.setColor(Color.blue);
    g.drawLine(x, baseline - ascent, x + stringWidth, baseline - ascent);
    g.setColor(Color.black);
    g.drawString(s, x, baseline);
}

From source file:Main.java

public void paint(Graphics g) {

    int fontSize = 20;

    Font font = new Font("TimesRoman", Font.PLAIN, fontSize);
    g.setFont(font);/*  w ww. j ava  2s .co m*/

    FontMetrics fm = g.getFontMetrics(font);

    String s = "www.java2s.com";

    int stringWidth = fm.stringWidth(s);

    int w = 200;
    int h = 200;

    int x = (w - stringWidth) / 2;
    int baseline = fm.getMaxAscent() + (h - (fm.getAscent() + fm.getMaxDecent())) / 2;
    int ascent = fm.getMaxAscent();
    int descent = fm.getMaxDecent();
    int fontHeight = fm.getMaxAscent() + fm.getMaxDecent();

    g.setColor(Color.white);
    g.fillRect(x, baseline - ascent, stringWidth, fontHeight);

    g.setColor(Color.gray);
    g.drawLine(x, baseline, x + stringWidth, baseline);

    g.setColor(Color.red);
    g.drawLine(x, baseline + descent, x + stringWidth, baseline + descent);

    g.setColor(Color.blue);
    g.drawLine(x, baseline - ascent, x + stringWidth, baseline - ascent);
    g.setColor(Color.black);
    g.drawString(s, x, baseline);

}