Example usage for java.awt Graphics drawString

List of usage examples for java.awt Graphics drawString

Introduction

In this page you can find the example usage for java.awt Graphics drawString.

Prototype

public abstract void drawString(AttributedCharacterIterator iterator, int x, int y);

Source Link

Document

Renders the text of the specified iterator applying its attributes in accordance with the specification of the java.awt.font.TextAttribute TextAttribute class.

Usage

From source file:TextLayoutCenter.java

public void drawString(Graphics g, String line, int wc, int lineW, int y) {
    g.drawString(line, (d.width - lineW) / 2, y);//center
}

From source file:Main.java

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

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

    g.drawString("www.java2s.com", 10, 20);
}

From source file:MainClass.java

public void paint(Graphics g) {
    int w = getSize().width;
    int midW = w / 2;

    g.drawString("XOR Mode", 0, 30);

    g.drawOval(7, 37, 50, 50);/*  w ww  .j a  va 2  s.co m*/

    g.setXORMode(Color.white);

    for (int i = 0; i < 15; i += 3) {
        g.drawOval(10 + i, 40 + i, 50, 50);
    }

    g.setPaintMode();

    g.drawString("Paint Mode", midW, 30);

    g.drawOval(midW + 7, 37, 50, 50);

    for (int i = 0; i < 15; i += 3) {
        g.drawOval(midW + 10 + i, 40 + i, 50, 50);
    }
}

From source file:MyComponent.java

protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    // Customize after calling super.paintComponent(g)

    g.drawString("string", 20, 20);
}

From source file:Main.java

public void paint(Graphics g) {
    int w = getSize().width;
    int midW = w / 2;

    g.drawString("XOR Mode", 0, 30);

    g.drawOval(7, 37, 50, 50);//w w  w .  j  av  a  2  s  . co  m

    g.setXORMode(Color.white);

    for (int i = 0; i < 15; i += 3) {
        g.drawOval(10 + i, 40 + i, 50, 50);
    }

    g.setPaintMode();

    g.drawString("Paint Mode", midW, 30);

    g.drawOval(midW + 7, 37, 50, 50);

    for (int i = 0; i < 15; i += 3) {
        g.drawOval(midW + 10 + i, 40 + i, 50, 50);
    }

}

From source file:MainClass.java

public void paint(Graphics g) {
    Font f = new Font("Serif", Font.PLAIN, 12);
    g.setFont(f);//  w ww  .j a v  a2  s .  co  m
    g.drawString("Serif - PLAIN - 12", 10, 30);

    f = new Font("Sanserif", Font.ITALIC, 10);
    g.setFont(f);
    g.drawString("Sanserif - ITALIC - 10", 10, 60);

    f = new Font("Monospaced", Font.BOLD | Font.ITALIC, 14);
    g.setFont(f);
    g.drawString("Monospaced - BOLD and ITALIC - 14", 10, 90);

    f = new Font("Dialog", Font.PLAIN, 12);
    g.setFont(f);
    g.drawString("Dialog - PLAIN - 12", 10, 120);

    f = new Font("DialogInput", Font.BOLD + Font.ITALIC, 10);
    g.setFont(f);
    g.drawString("DialogInput - BOLD and ITALIC - 10", 10, 150);
}

From source file:painting.SwingPaintDemo2.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);

    // Draw Text/*from www  .  j a v  a  2  s. co  m*/
    g.drawString("This is my custom Panel!", 10, 20);
}

From source file:Main.java

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.setFont(new Font("arial", Font.PLAIN, 24));
    g.drawString("java2s.com", 200, 200);
}

From source file:AppletMethods.java

public void paint(Graphics g) {
    g.drawString("Welcome to Java", 50, 50);
}

From source file:painting.SwingPaintDemo3.java

protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawString("This is my custom Panel!", 10, 20);
    g.setColor(Color.RED);//from   w  w  w  . ja va2  s. co  m
    g.fillRect(squareX, squareY, squareW, squareH);
    g.setColor(Color.BLACK);
    g.drawRect(squareX, squareY, squareW, squareH);
}