简体   繁体   English

如何使用GreenFoot API使字体加粗?

[英]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.

相关问题 Greenfoot:如何做到这一点,所以我一次按下一个按钮,它就一直起作用? - Greenfoot: How do I make it so I press a button once and it keeps acting? 如何使drawString()文本变为粗体? - How do I make drawString() text bold? 我如何将文本更改为粗体而不更改字体 - How do I change text to bold w/o changing font 如何在java对话框中使字体变粗? - How to make font bold in java dialogue box? 如何使TreeViewer单元格的一部分变为粗体? - How do I make part of a TreeViewer cell bold? 我想制作一个正则表达式来检查每一行,如果12 ^这来了,那么我想使行粗体并使字体大小为12如何实现这一目标? - I want to Make a Regex to check at each line if <b>12^ this comes then i want to make the line bold and make the font size of 12 How to achieve this? 如何在TextView中以粗体和多色显示文本 - How do I show text in my TextView with bold and multi coloured 我在为Greenfoot MyWorld类设置颜色时遇到麻烦 - I am having trouble to set color to my Greenfoot MyWorld class 如何使AlertDialog以等宽字体显示其文本? - How do I make my AlertDialog display its text in monospace font? 如何在Java中以粗体显示消息框中的特定单词(变量)? - How do I make a specific word (variable) in a message box bold in Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM