Code:
package server.model.players.buttons;
import java.util.*;
/*
* Author - Fritz (L Lawliet/TheRedArmy)
* Contains all of the registered buttons and methods to add and run them
*/
public class ButtonHandler {
/*
* Adds a button to the map
* @param id - The button's id
* @param btn - The button containing the onClick method
*/
public static void registerButton(int id, Button btn) {
gameButtons.put(id, btn);
}
/*
* Checks to see if the map contains the button and if it does, it runs the button's onClick method
* @param id - Id of the button
*/
public static void runButton(int id) {
if(gameButtons.get(id) != null) {
gameButtons.get(id).onClick();
}
}
/*
* Map containing all of the buttons and their ids
*/
public static HashMap<Integer, Button> gameButtons = new HashMap<Integer, Button>();
}
Add to ClickingButtons.java