public class Play extends World implements ButtonResponder
{
private World firstWorld;
/**
* Constructor for objects of class OtherWorld.
*/
public Play(GreenfootImage background, World Menu)
{
super(1920, 1080, 1);
//Sets firstWorld to Menu so that it goes back to the Main Menu.
firstWorld = Menu;
//Adds in the title class as an object at a set position on screen.
addObject(new Title(), 960, 100);
//Adds in a button that will be used to go back to the Main Menu when called.
addObject(new Button("1", this), 960, 250);
addObject(new Button("Back", this), 380, 900);
}
/**
* All buttons in the MenuWorld can call this method.
*/
public void buttonPressed(Button button)
{
//If the button labled Back is clicked then this statement is executed.
if ("Back".equals(button.getTitle()) ) {
//Changes the world back to the MainMenu class
Greenfoot.setWorld(firstWorld);
}
if ("1".equals(button.getTitle()) ) {
addObject(new Button("2", this), 960, 250);
}
}
}
All the rest of this code works, but I want to make it so that I can remove the button that was created with a "1" as text when it is clicked. Either that or I plan to update it with a "2" instead. If anyone can tell me the way to remove the button then that'd be awesome, thanks!
