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

2012/12/29

Pop up message

Peach Peach

2012/12/29

#
Hi, I was just wondering how I should declare the variable "colour" in the code because I cannot compile it as it says cannot find variable colour. import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class PopUpMessage here. * * @author (your name) * @version (a version number or a date) */ public class PopUpMessage extends Actor { public PopUpMessage(String message) { // create an image object: message, fontSize, fg color, bg color GreenfootImage image = new GreenfootImage(message, 50, Colour.BLACK, Colour.WHITE); // draw a red border on the image image.setColor(Color.RED); image.drawRect(0, 0, image.getWidth()-1, image.getHeight()-1); // assign the image to the actor setImage(image); } public void gameOver(String message) { PopUpMessage popUp = new PopUpMessage(message); addObject(popUp, getWidth() / 2, getHeight() / 2); Greenfoot.stop(); } }
danpost danpost

2012/12/29

#
First 'Colour' is not recognized by the compiler because you do not have a 'Colour' class that is available to it (so it then assumes it is a variable name; and since you do not declare one with that name, the error message ensues). Second, the class you want to have available to it is spelt 'Color'; and the way to make that class available is it add another 'import' statement at the top of your class code:
import java.awt.Color;
After adding that statement, you only need correct the spelling in your code.
You need to login to post a reply.