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

2018/10/30

Is there a way to change font styles in Greenfoot?

patches312 patches312

2018/10/30

#
private void makeImage(String title, String prefix, int score)
    {
        GreenfootImage image = new GreenfootImage(WIDTH, HEIGHT);

        image.setColor(new Color(225,50,120, 145));
        image.fillRect(0, 0, WIDTH, HEIGHT);
        image.setColor(new Color(175, 0, 100, 128));
        image.fillRect(5, 5, WIDTH-10, HEIGHT-10);
        Font font = image.getFont();
        font = font.deriveFont(FONT_SIZE);
        image.setFont(font);
        image.setColor(Color.WHITE);
        image.drawString(title, 60, 100);
        image.drawString(prefix + score, 60, 200);
        setImage(image);
    }
danpost danpost

2018/10/30

#
patches312 wrote...
Is there a way to change font styles in Greenfoot?
If you mean to change to bold or italicized, you can create a new Font with those characteristics. Without testing, I think you could change line 10 to something like:
font = new Font(font.getName(), true, true, FONT_SIZE);
You need to login to post a reply.