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

2025/3/13

I want to add a white box with fixed width and height

Coolboys Coolboys

2025/3/13

#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public class dialoog extends Actor
{
    private int nr2 = 0;
    private String text1 = "De quantumchip is gestolen";
    private String text2 = "Wie was het?";
    public dialoog(int nr){
        String tekst;
 
        switch (nr){ //Veranderd van text naar de case nr
            case 1:
                tekst = text1;
                break;
            case 2:
                tekst = text2;
                break;
            default:
                tekst="";
                break;
        }
         
        GreenfootImage image = new GreenfootImage(tekst,50, Color.RED, Color.GRAY);
        setImage(image);
 
    }
nothing that i do seems to work, what do i need to do?
danpost danpost

2025/3/14

#
Coolboys wrote...
I want to add a white box with fixed width and height << Code Omitted >>
At line 20, create the box and fill it with white. Then, after creating the text image, draw it into the box:
1
2
3
4
5
6
GreenfootImage box = new GreenfootImage(560, 50);
box.setColor(Color.WHITE);
box.fill();
GreenfootImage txt = new GreenfootImage(tekst, 50, Color.RED, new Color(0, 0, 0, 0));
box.drawImage(txt, (box.getWidth()-txt.getWidth())/2, 0);
setImage(box);
You need to login to post a reply.