Java Draw String drawString(String txt, int x, int y, Graphics g)

Here you can find the source of drawString(String txt, int x, int y, Graphics g)

Description

draw String

License

Open Source License

Declaration

public static void drawString(String txt, int x, int y, Graphics g) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.*;

import java.awt.image.*;

public class Main {
    private static BufferedImage[] GUI_GLYPH_CHARS;

    public static void drawString(String txt, int x, int y, Graphics g) {
        int x2 = 0;
        for (int v = 0; v < txt.length(); v++) {
            char c = txt.charAt(v);
            drawChar(c, x2 + x, y, g);//from  w  w  w .  ja v a2s. c om
            x2 += 8;
        }
    }

    public static void drawChar(char c, int x, int y, Graphics g) {
        BufferedImage img = null;
        switch (c) {
        case ' ':
            img = GUI_GLYPH_CHARS[0];
            break;
        case '\u0263':
            img = GUI_GLYPH_CHARS[1];
            break;
        case '!':
            img = GUI_GLYPH_CHARS[33];
            break;
        case '"':
            img = GUI_GLYPH_CHARS[34];
            break;
        case '#':
            img = GUI_GLYPH_CHARS[35];
            break;
        case '$':
            img = GUI_GLYPH_CHARS[36];
            break;
        case '%':
            img = GUI_GLYPH_CHARS[37];
            break;
        case '&':
            img = GUI_GLYPH_CHARS[38];
            break;
        case '\'':
            img = GUI_GLYPH_CHARS[39];
            break;
        case '(':
            img = GUI_GLYPH_CHARS[40];
            break;
        case ')':
            img = GUI_GLYPH_CHARS[41];
            break;
        case '*':
            img = GUI_GLYPH_CHARS[42];
            break;
        case '+':
            img = GUI_GLYPH_CHARS[43];
            break;
        case ',':
            img = GUI_GLYPH_CHARS[44];
            break;
        case '-':
            img = GUI_GLYPH_CHARS[45];
            break;
        case '.':
            img = GUI_GLYPH_CHARS[46];
            break;
        case '/':
            img = GUI_GLYPH_CHARS[47];
            break;
        case '0':
            img = GUI_GLYPH_CHARS[48];
            break;
        case '1':
            img = GUI_GLYPH_CHARS[49];
            break;
        case '2':
            img = GUI_GLYPH_CHARS[50];
            break;
        case '3':
            img = GUI_GLYPH_CHARS[51];
            break;
        case '4':
            img = GUI_GLYPH_CHARS[52];
            break;
        case '5':
            img = GUI_GLYPH_CHARS[53];
            break;
        case '6':
            img = GUI_GLYPH_CHARS[54];
            break;
        case '7':
            img = GUI_GLYPH_CHARS[55];
            break;
        case '8':
            img = GUI_GLYPH_CHARS[56];
            break;
        case '9':
            img = GUI_GLYPH_CHARS[57];
            break;
        case ':':
            img = GUI_GLYPH_CHARS[58];
            break;
        }
        g.drawImage(img, x, y, null);
    }
}

Related

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