Hello,
The goal is as followed:
On the right side you have a small interface with 3 icons. When the user clicks on 1 of the 3 icons, a small menu with multiple text-lines appears underneath it. When the user clicks on a different icon, the previous list of text (menu) gets replaced by the text that is related to the currently clicked icon.
I have the following code:
import greenfoot.*;
public class btnPolice extends Buttons {
public btnPolice() {
if (Greenfoot.mouseClicked(this)) {
ShowMenu show = new ShowMenu();
//getWorld().addObject(show, 650, 100);
show._Selection = 1;
}
}
}
import greenfoot.*;
import java.awt.color.*;
import java.awt.Color;
public class ShowMenu extends Buttons
{
int _Selection;
public void act() {
ShowSelection();
}
public void ShowSelection()
{
if (_Selection == 1) {
setImage(new GreenfootImage("Hello world!", 18, Color.GREEN, Color.BLACK));
}
else if (_Selection == 2) {
setImage(new GreenfootImage("Hello world!\n" +
"selection 2", 18, Color.GREEN, Color.BLACK));
}
else if (_Selection == 3) {
setImage(new GreenfootImage("Hello world!\n" +
"selection 3", 18, Color.GREEN, Color.BLACK));
}
else {
}
}
}
The problem is, when I click the icon (First code in this post) nothing happens. What am I doing wrong when developing code in the Actor classes? When developing in the World classes, objects do get added.
Thanks!