Java Draw String drawStringAt(Graphics g, String t, int x, int y, int where)

Here you can find the source of drawStringAt(Graphics g, String t, int x, int y, int where)

Description

_more_

License

Open Source License

Parameter

Parameter Description
g _more_
t _more_
x _more_
y _more_
where _more_

Declaration

public static void drawStringAt(Graphics g, String t, int x, int y, int where) 

Method Source Code

//package com.java2s;
/**//w  ww  .j  a  v  a 2s.  co m
* Copyright (c) 2008-2015 Geode Systems LLC
* This Software is licensed under the Geode Systems RAMADDA License available in the source distribution in the file 
* ramadda_license.txt. The above copyright notice shall be included in all copies or substantial portions of the Software.
*/

import java.awt.*;

public class Main {
    /** _more_ */
    public static final int PT_NW = 1;
    /** _more_ */
    public static final int PT_NE = 3;
    /** _more_ */
    public static final int PT_SW = 7;
    /** _more_ */
    public static final int PT_SE = 9;

    /**
     * _more_
     *
     * @param g _more_
     * @param t _more_
     * @param x _more_
     * @param y _more_
     * @param where _more_
     */
    public static void drawStringAt(Graphics g, String t, int x, int y, int where) {
        FontMetrics fm = g.getFontMetrics();
        int w = fm.stringWidth(t);
        int h = fm.getMaxAscent() + fm.getMaxDescent();
        switch (where) {

        case PT_NW:
            g.drawString(t, x, y + h);

            break;

        case PT_NE:
            g.drawString(t, x - w, y + h);

            break;

        case PT_SW:
            g.drawString(t, x, y);

            break;

        case PT_SE:
            g.drawString(t, x - w, y);

            break;
        }
    }
}

Related

  1. drawString(Graphics2D graphics, String text, double x, double y, boolean centerHorizontal, boolean centerVertical, Color backgroundColor)
  2. drawString(Image img, String text, Color color)
  3. drawString(String pString, Graphics2D pG, int pX, int pY, int pWidth, int pHeight, boolean pYOverflow, boolean pShrinkWords, String pJustification, boolean pDraw)
  4. drawString(String txt, int x, int y, Graphics g)
  5. drawStringAlignCenter(Graphics2D g2d, String s, int x, int y)
  6. drawStringAtPoint(Graphics g, String s, Point p)
  7. drawStringEx(Graphics g1, String s, Font font, Rectangle rect, int align, int valign)
  8. drawStringInBox(Graphics g, String string, int x, int y)
  9. drawStringLeft(Graphics2D g, String text, Rectangle rect, int fontHeight, Color c)