I have a scenario where I used the Greenfoot Image setFont along with java's font in a few of my classes like this:
This used to function perfectly; however I haven't programmed in a long time and recently updated Greenfoot and now I get an error at gi.setFont(f).
Does anyone know how to fix this? if so it would be greatly appreciated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Font; import java.awt.font.FontRenderContext; import java.awt.geom.AffineTransform; /** * Write a description of class Message here. * * @author (your name) * @version (a version number or a date) */ public class Message extends Actor { public static int messageCount= 0 ; private int startingMsgs; public static int messagesDeleted= 0 ; public static int numberOfMessages= 0 ; public Message(String text) { startingMsgs=messageCount; numberOfMessages++; messageCount++; AffineTransform affinetransform = new AffineTransform(); FontRenderContext frc = new FontRenderContext(affinetransform, true , true ); Font f = new Font( "Times New Roman" , Font.ITALIC, 25 ); int textWidth = ( int )(f.getStringBounds(text, frc).getWidth()); GreenfootImage gi= new GreenfootImage(textWidth+ 8 , 100 ); gi.setFont(f); //I'm getting an error here at (f) gi.setColor(Color.WHITE); gi.drawString(text, 2 , 20 ); setImage(gi); } |