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

2017/12/4

Problem with java.awt.Color and java.awt.Font

ryan22 ryan22

2017/12/4

#
I'm having trouble inserting a colors and fonts into my code even though I imported both java.awt.Color and java.awt.Font. It gives me errors in lines 15, 17, and 19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import greenfoot.*;
import java.lang.Object;
import java.awt.Color;
import java.awt.Font;
public class Score extends Actor
{
    public Score(){
        GreenfootImage newimage = new GreenfootImage(100, 50);
        setImage(newimage);
    }
    public void setScore(int score){
        GreenfootImage newimage = getImage();
        newimage.clear();
        Font f = new Font("Comis Sans MS", Font.PLAIN, 32);
        newimage.setFont(f);
        Color c = new Color(127, 127, 127, 127);
        newimage.setColor(c);
        newimage.fill();
        newimage.setColor(Color.RED);
        newimage.drawString("" +score,200,20);
        setImage(newimage);
    }
}
danpost danpost

2017/12/4

#
The newer versions of greenfoot have the 'setColor' and 'setFont' methods using parameters of type 'greenfoot.Color' and 'greenfoot.Font'. Remove the import lines 3 and 4 and replace 'Font.PLAIN' on line 14 with 'false, false' to conform to the 'greenfoot.Font' constructor.
You need to login to post a reply.