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

2020/6/4

how to make appear text while clicking on an image of a button?

ronald ronald

2020/6/4

#
thank you for the help
Yehuda Yehuda

2020/6/4

#
You can use Greenfoot.mousePressed. And then an additional condition (Greenfoot.mouseClicked) to change back. It's only true after the mouse has been released. I'm not clear in what you mean by "appear text".
ronald ronald

2020/6/5

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

/**
 * Write a description of class Button here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Button extends Actor
{
    public Button()
    {
        setImage("button.png");
    }
    
    /**
     * Act - do whatever the Button wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
        clickButton();
         
    }
    
    public void clickButton()
    {
        GreenfootImage gfim = new GreenfootImage(900,600);
        if(Greenfoot.mouseClicked("button.png")==true)
        {
            
            gfim.drawString("fi", 200, 200);
            
        }      
    }
}

I give you the code, you will understand, by show text i mean drawstring
danpost danpost

2020/6/5

#
How does drawing text on a newly created image help?
ronald ronald

2020/6/5

#
when I click on the image of the button, the drawing of the text appears next to it, not that it works or otherwise create the button in the shape of a drawing
danpost danpost

2020/6/5

#
ronald wrote...
when I click on the image of the button, the drawing of the text appears next to it, not that it works or otherwise create the button in the shape of a drawing
Are you trying to replace the button image with the image of the text "fi"? If not, you need to set this new image to another actor or draw the image onto the background image.
ronald ronald

2020/6/5

#
no i am not trying to replace I just want to display "fi" or something just next to the button image by clicking
danpost danpost

2020/6/5

#
Another option is to use the World instance method showText.
ronald ronald

2020/6/6

#
thank you
You need to login to post a reply.