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

2021/1/28

Font Error

jacquelinereilly jacquelinereilly

2021/1/28

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Font; 
/**
 * Write a description of class Score here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Score extends Actor
{
    font f = new Font();
 
    public Score () {
        GreenfootImage newImage = new GreenfootImage (100, 50);
        setImage (newImage);
}

  public void setScore (int score) {
     GreenfootImage newImage = getImage (); 
     newImage.clear ();
     
     Font f = new Font ("Comic Sans MS", Font.PLAIN, 32);
     newImage.setFont (f);
     
     Color c = new Color (127, 127, 127, 127);
     newImage.setColor (c);
     newImage.fill ();
     newImage.drawString ("" + score, 30, 30);
     setImage (newImage);
    }
}
danpost danpost

2021/1/28

#
Change line 11 to:
Font f;
and line 22 to:
f = new Font("Comic Sans MS", Font.PLAIN, 32);
jacquelinereilly jacquelinereilly

2021/1/28

#
That's great!! Thanks Dan. Right as I think I get something.... the error I am receiving now is cannot find varible- PLAIN
danpost danpost

2021/1/28

#
jacquelinereilly wrote...
That's great!! Thanks Dan. Right as I think I get something.... the error I am receiving now is cannot find varible- PLAIN
Use:
f = new Font("Comic Sans MS", false, false, 32);
jacquelinereilly jacquelinereilly

2021/1/28

#
Awesome!!! Thank you so much
You need to login to post a reply.