View Javadoc

1   package de.jos.game.objects.buttons;
2   
3   import de.jos.game.objects.screen.AbstractGameObject;
4   import de.jos.game.objects.screen.Screen;
5   
6   public class BackButton extends GameButton {
7   
8     /***
9      * Create a BackButton at the position.
10     * 
11     * @param gameObject
12     * @param x
13     * @param y
14     */
15    public BackButton(AbstractGameObject gameObject, int x, int y, Screen backScreen) {
16      super(gameObject.getString("menu.back"), x, y, 0, 0, gameObject);
17      // callback registrieren
18      setButtonClickCallback(new BackButtonClickCallback(gameObject, backScreen));
19    }
20  
21    @Override
22    public Action getAction() {
23      return Action.BACK;
24    }
25  
26    /***
27     * Callback fuer einen Button click.
28     * 
29     * @author root
30     * 
31     */
32    private static final class BackButtonClickCallback implements ButtonClickCallback {
33  
34      AbstractGameObject gameObject = null;
35      Screen backScreen = null;
36  
37      public BackButtonClickCallback(AbstractGameObject gameObject, Screen backScreen) {
38        this.gameObject = gameObject;
39        this.backScreen = backScreen;
40      }
41  
42      /***
43       * {@inheritDoc}
44       */
45      public void performClickAction() {
46        gameObject.setNextScreen(backScreen);
47      }
48  
49    }
50  
51  }