|
GTGE API | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface GameFont
GameFont interface is an interface to draw text with alignment.
| Field Summary | |
|---|---|
static int |
CENTER
Text alignment: center alignment. |
static int |
JUSTIFY
Text alignment: justify alignment. |
static int |
LEFT
Text alignment: left alignment. |
static int |
RIGHT
Text alignment: right alignment. |
| Method Summary | |
|---|---|
int |
drawString(Graphics2D g,
String s,
int x,
int y)
Draw a single line string into graphics context. |
int |
drawString(Graphics2D g,
String s,
int alignment,
int x,
int y,
int width)
Draw a single line string into graphics context with specified alignment. |
int |
drawText(Graphics2D g,
String text,
int alignment,
int x,
int y,
int width,
int vspace,
int firstIndent)
Draw multiple line text into graphics context. |
int |
getHeight()
Returns the height of this font in pixel. |
int |
getWidth(char c)
Returns the width of char c in pixel. |
int |
getWidth(String st)
Returns the width of String st in pixel. |
boolean |
isAvailable(char c)
Returns whether the specified char c is available to draw
by this game font. |
| Field Detail |
|---|
static final int LEFT
static final int RIGHT
static final int CENTER
static final int JUSTIFY
| Method Detail |
|---|
int drawString(Graphics2D g,
String s,
int x,
int y)
g - the graphics contexts - the string to be drawnx - the x screen coordinate to draw the texty - the y screen coordinate to draw the text
x coordinate to draw next text.
int drawString(Graphics2D g,
String s,
int alignment,
int x,
int y,
int width)
g - the graphics contexts - the string to be drawnalignment - text alignment: LEFT, RIGHT, CENTER, or JUSTIFYx - the x screen coordinate to draw the texty - the y screen coordinate to draw the textwidth - width of the text
x coordinate to draw next text.
int drawText(Graphics2D g,
String text,
int alignment,
int x,
int y,
int width,
int vspace,
int firstIndent)
Example to write two paragraph text:
// creates bounding box, to ensure the paragraph exactly in the box
g.drawRect(10, 10, 620, 100);
int nexty = GameFont.drawText(g,
"Paragraph one, sample paragraph using GameFont drawText.",
GameFont.LEFT, 10, 10, 620, 0, 50);
GameFont.drawText(g,
"Paragraph two, notice that each paragraph have 50 pixel indentation.",
GameFont.LEFT, // left alignment
10, // x
nexty, // y
620, // width
0, // no additional vertical spacing
50); // 50 pixel indentation
g - graphics context where the text will be drawntext - text to be drawnalignment - text alignment: LEFT, RIGHT, CENTER, or JUSTIFYx - text x coordinatey - text y coordinatewidth - width per linevspace - additional vertical spacing, in pixelfirstIndent - first line indentation, in pixel
y coordinate to draw next paragraph.LEFT,
RIGHT,
CENTER,
JUSTIFYint getWidth(String st)
String st in pixel.
int getWidth(char c)
char c in pixel.
int getHeight()
boolean isAvailable(char c)
char c is available to draw
by this game font.
|
GTGE API | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||