[英]How do I make my font bold with the GreenFoot API?
I have this font constructor written to make the font I want BOLD, however whenever I try to compile, it tells me the error Cannot find symbol - variable BOLD
. 我已经写了这个字体构造函数来制作我想要的BOLD字体,但是,每当我尝试编译时,它都会告诉我错误:
Cannot find symbol - variable BOLD
。
Font font = new Font("Arial",font.BOLD, 40);
These are the classes I'm importing: 这些是我要导入的类:
import greenfoot.*;
import java.util.*;
import greenfoot.Font;
import java.lang.Class;
If anyone knows the probably quick fix it'd be much appreciated. 如果有人知道可能的快速修复方法,将不胜感激。
You're using the constructor incorrectly. 您使用的构造器不正确。 Per the documentation :
根据文档 :
Constructor and Description
构造函数和描述
Font(java.lang.String name, boolean bold, boolean italic, int size)
Creates a font from the specified font name, size and style.
根据指定的字体名称,大小和样式创建字体。
It should be like so (bold, non-italic): 它应该像这样(粗体,非斜体):
Font font = new Font("Arial", true, false, 40);
You were using the constructor incorrectly and attempt to access an instance variable that did not exist. 您使用了错误的构造函数,并试图访问一个不存在的实例变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.