|
Code Samples Index
These code examples and other materials are subject to Sun Microsystems, Inc.
Legal Terms
Drawing Simple Text
// Set the desired font if different from default font.
Font font = new Font("Serif", Font.PLAIN, 12);
g2d.setFont(font);
// Draw the string such that its base line is at x, y.
g2d.drawString("aString", x, y);
// Draw the string such that the top-left corner
// is at x, y.
FontMetrics fontMetrics = g2d.getFontMetrics();
g2d.drawString(
"aString", x, y+fontMetrics.getAscent());
|
Examplets provided by permission of the publisher, Addision-Wesley,
and Author Patrick Chan.
Order this book from Amazon
|