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

2020/11/7

Pop-up Message

PascalFischer PascalFischer

2020/11/7

#
Hi, I found a Code, were I can make a Pop-up Message, but this Code doesn't work for me, so I'd like to ask, what is wrong with it.
import greenfoot.*;
import java.awt.Color;
 
public class GameOver extends Actor
{
    String text = " GAME OVER! \n YOU WIN! ";
    GreenfootImage inner = new GreenfootImage(text, 48, Color.black, new Color(0, 0, 0, 96));
 
    public GameOver()
    {
    }
 
    // create a gameover image the size of the world
    public void addedToWorld(World world)
    {
        int wide = world.getWidth();
        int high = world.getHeight();
        GreenfootImage outer = new GreenfootImage(wide, high);
        int leftX = (wide - inner.getWidth())/2;
        int topY = (high - inner.getHeight())/2;
        outer.drawImage(inner, leftX, topY);
        setImage(outer);
    }
 
    // the following is optional
    // remove pop-up when clicked on
    public void act()
    {
        if (Greenfoot.mouseClicked(this))
        {
             getWorld().removeObject(this);
        }
    }
}
I always get the Error: Jawa.awt.Color cannot be converted to Greenfoot.Color, at this part of the Code
GreenfootImage inner = new GreenfootImage(text, 48, Color.black, new Color(0, 0, 0, 96));
I would love, if someone could help me.
Super_Hippo Super_Hippo

2020/11/7

#
Remove line 2. With some update, Greenfoot introduced its own classes for Color and Font and isn’t using java.awt anymore.
PascalFischer PascalFischer

2020/11/7

#
thanks it works now
You need to login to post a reply.