This site requires JavaScript, please enable it in your browser!
Greenfoot back
Wasupmacuz
Wasupmacuz wrote ...

2017/10/15

.setFont no longer compatible with java.awt.Font?

Wasupmacuz Wasupmacuz

2017/10/15

#
I have a scenario where I used the Greenfoot Image setFont along with java's font in a few of my classes like this:
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);
    }
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.
danpost danpost

2017/10/15

#
See the second note at the bottom of this discussion post by davmac.
Wasupmacuz Wasupmacuz

2017/10/15

#
danpost wrote...
See the second note at the bottom of this discussion post by davmac.
So Greenfoot is pulling away from java.awt for HTML5? I like Java much more than JavaScript, so if this is the case do you know where to get the latest update before this conversion?
danpost danpost

2017/10/15

#
Wasupmacuz wrote...
do you know where to get the latest update before this conversion?
See the bottom of the Download page for 'Old versions'. I guess you would want the version 3.0.3 as I think they added the Color and Font classes to greenfoot in version 3.1.0.
Wasupmacuz Wasupmacuz

2017/10/15

#
danpost wrote...
Wasupmacuz wrote...
do you know where to get the latest update before this conversion?
See the bottom of the Download page for 'Old versions'. I guess you would want the version 3.0.3 as I think they added the Color and Font classes to greenfoot in version 3.1.0.
Thanks Dan!
You need to login to post a reply.