【发布时间】:2015-07-12 20:51:08
【问题描述】:
尝试写一个类:
private void gameLevel(Graphics g) {
try {
InputStream fnt_stream = getClass().getResourceAsStream("resources/iomanoid.ttf");
Font myFont = Font.createFont(Font.TRUETYPE_FONT, fnt_stream);
Font Iomanoid = new Font("Iomanoid", Font.BOLD, 40);
String msg = "Level";
g.setColor(Color.black);
g.setFont(Iomanoid);
g.drawString(msg, 111,111);
} catch (Exception ex) {
System.out.println(ex);
}
显示消息,但未使用指定的字体。
【问题讨论】:
-
顺便说一句,您忘记
close()输入流。使用try-finally或try-with-resources。哦,fnt_stream不符合正确的 Java 风格(只允许 MULTI_WORD_CONSTANTS 包含下划线)。
标签: java fonts graphics2d truetype