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

2021/7/11

Pop-up message

StndRed StndRed

2021/7/11

#
I've been looking at old threads about pop-up messages and have been unable to get a working code. I have tried the Game-Over code and it gives me an "illegal start of expression" error that I have been unable to fix. If anyone has a more current code or if anyone has any advice for the error i would greatly appreciate it. Thanks a bunch StndRed
danpost danpost

2021/7/12

#
StndRed wrote...
it gives me an "illegal start of expression" error ... f anyone has any advice for the error i would greatly appreciate it.
Need codes producing error to fix.
StndRed StndRed

2021/7/12

#
public void act()
    {
        String text = "Cuidar de uno mismo es el primer paso para alcanzar tus objetivos. \n Tú eres el mejor.";
        GreenfootImage inner = new GreenfootImage(text, 48, Color.black, new Color(0, 0, 0, 96));
 
    public clown()
    {
    } 
  
        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);
        }
    public void act()
    {
        if (Greenfoot.mouseClicked(this))
        {
             getWorld().removeObject(this);
        }
    }
}
public clown and public void is where the error is shown,
Super_Hippo Super_Hippo

2021/7/12

#
You have two act methods. You should only have one. You can probably remove lines 6–8 if nothing is in there.
StndRed StndRed

2021/7/12

#
Ok, Im still getting the error with the public void lines. They were in the original code. But im unsure whether or not they should be in there now.
danpost danpost

2021/7/13

#
Replace line 1 with line 7. Then remove lines 7 (the replacement line) and 8.
StndRed StndRed

2021/7/13

#
Ok Thanks for all your help! Just one last thing, I cant seem to get the color right. From what i read Greenfoot no longer imports java.awt.Color, so im unsure how to dictate the color of the text. What is the most effective way to do that? Thanks again!
Super_Hippo Super_Hippo

2021/7/13

#
You can use the Color class provided by Greenfoot. It is very similar to java.awt.Color. You have to create an image, set the color and then use the drawString method to draw text with the given text color to the background. However, if the text on the image is everything you need, it might be enough to use another constructor for the GreenfootImage class. You can set the text color (‘forgreound’) directly. Check the API here: https://www.greenfoot.org/files/javadoc/greenfoot/GreenfootImage.html
You need to login to post a reply.