Calls g.drawString(s, x, y) after setting the color to c. - Java 2D Graphics

Java examples for 2D Graphics:Color

Description

Calls g.drawString(s, x, y) after setting the color to c.

Demo Code


//package com.java2s;
import java.awt.*;

public class Main {
    /** Calls g.drawString(s, x, y) after setting the
     *  color to c. Resets the color after drawing.
     */*from w  w w.  j av  a 2  s . com*/
     * @param g The Graphics object.
     * @param s The string to be drawn.
     * @param x The left side of the string.
     * @param y The <B>bottom</B> (not top) of the string.
     * @param c The color in which to draw the string.
     */

    public static void drawString(Graphics g, String s, int x, int y,
            Color c) {
        Color origColor = g.getColor();
        g.setColor(c);
        g.drawString(s, x, y);
        g.setColor(origColor);
    }

    /** Calls g.drawString(s, x, y) after setting the
     *  font to f. Resets the font after drawing.
     *
     * @param g The Graphics object.
     * @param s The string to be drawn.
     * @param x The left side of the string
     * @param y The <B>bottom</B> (not top) of the string.
     * @param f The font in which to draw the string.
     */

    public static void drawString(Graphics g, String s, int x, int y, Font f) {
        Font origFont = g.getFont();
        g.setFont(f);
        g.drawString(s, x, y);
        g.setFont(origFont);
    }

    /** Calls g.drawString(s, x, y) after setting the
     *  font to f and the color to c. Resets the font
     *  and color after drawing.
     *
     * @param g The Graphics object.
     * @param s The string to be drawn.
     * @param x The left side of the string
     * @param y The <B>bottom</B> (not top) of the string.
     * @param f The font in which to draw the string.
     * @param c The color in which to draw the string.
     */

    public static void drawString(Graphics g, String s, int x, int y,
            Font f, Color c) {
        Font origFont = g.getFont();
        g.setFont(f);
        drawString(g, s, x, y, c);
        g.setFont(origFont);
    }
}

Related Tutorials