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

2017/3/14

Color.BLACK not working!

11870 11870

2017/3/14

#
I am very new to Greenfoot and I want to display my score in black. For some reason, this shows an error at Color.BLACK. It says "incompatible types:java.awt.Color cannot be converted to greenfoot.Color". It shows the exact same error in other scripts where I want to display any text. Please help!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
 * Write a description of class youwin here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class youwin extends Actor
{
    /**
     * Act - do whatever the youwin wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public youwin()
    {
        GreenfootImage image = new GreenfootImage("YOU WIN!", 20, Color.BLACK, Color.WHITE);
        setImage(image);
    }
   
}
davmac davmac

2017/3/14

#
It looks like you've taken code from an older version of Greenfoot and imported into Greenfoot 3.1.0. But you didn't let it update the code for you :) Just remove the "import java.awt.Color;" line (2nd line).
11870 11870

2017/3/14

#
Thank you so much! It works now!
InnocentMe InnocentMe

2017/3/14

#
Just remove the "import java.awt.Color;" line (2nd line). and change it with import greenfoot.Color; and its works.
Super_Hippo Super_Hippo

2017/3/14

#
Even though the comment in line 1 could mislead, 'import greenfoot.*;' also imports all other classes from the greenfoot package, so there is no need to import greenfoot.Color after already importing all greenfoot classes.
11870 11870

2017/3/23

#
Thank you for all of the help everybody! I have now finished making my first video game and am working on my second one. Thank you all!
You need to login to post a reply.