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

2013/6/27

Changing font in counter.class

davemib123 davemib123

2013/6/27

#
Hi, I've imported the counter class how do I change its font to something that looks more like this: http://www.ffonts.net/Perfect-DOS-VGA-437.font
Gevater_Tod4711 Gevater_Tod4711

2013/6/27

#
To change the font of an image you can use the method setFont(Font font) int GreenfootImage and java.awt.Font. But I don't know how to set the font to exactly this font in your example.
davemib123 davemib123

2013/6/27

#
So just as a test, I tried this:
    public Counter()  
    {  
      
        value = 0;
        target = 0;
        this.prefix = prefix;
        updateImage();
        GreenfootImage image = getImage();
        Font font = image.getFont();
        image.setFont(new java.awt.Font("Times New Roman", java.awt.Font.PLAIN, 8)); 
}
Doesnt work - font stays the same. Not sure if this would have anything to do with it:
 private void updateImage()  
    {  
        int fontSize = 8;
        setImage(new GreenfootImage(prefix+": "+value, fontSize, textColor, TRANSPARENT)); 
    } 
Gevater_Tod4711 Gevater_Tod4711

2013/6/27

#
Maybe the class java.awt.GraphicsEnvironment can help you. Using the method GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames() you can get a list of all known Font familys. Also a list of all fonts is to be found there.
You need to login to post a reply.