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

2017/5/18

color help

batuts1 batuts1

2017/5/18

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;

public class CardWorld  extends World
{
   private  Deck d;
   private Card [] hand=new Card[5];
   private int c=0;
   boolean keyCaptured=false;
   Question q;
   Info info;
    public CardWorld()
    {    
        // Create a new world with 20x20 cells with a cell size of 10x10 pixels.
        super(500,400,1);
        GreenfootImage bg=getBackground();
        bg.setColor(new Color(0,128,0));
        bg.fill();
        d=new Deck();
        d.shuffle();
        setUp();
    }
batuts1 batuts1

2017/5/18

#
there is something wrong with line 17, it has (new Color(0,128,0)); underlined in red and the error says incompatible types: java.awt.Color cannot be converted to greenfoot.Color
danpost danpost

2017/5/18

#
Try 'new java.awt.Color(0, 128, 0)'. Or, try removing line 2 and using 'new Color(0, 128, 0, 255)'.
Yehuda Yehuda

2017/5/19

#
The only thing needed to be done is:
bg.setColor(new greenfoot.Color(0,128,0));
If that's the error then that means that there is a greenfoot.Color class, meaning that the GreenfootImage.setColor method needs a greenfoot.Color (not a java.awt.Color). The error is coming since there are two Color classes you can be referring to, so you have to specify which one you're talking about.
You need to login to post a reply.