@Override public void init(GameContainer gc) throws SlickException{ super.init(gc); TSTextLabel label = new TSTextLabel(gc, getWidth() / 2, getHeight() / 8, " Options "); TSBoxLabel box = new TSBoxLabel(gc, label, Color.green, Color.black); tsftb = new TSFocusTextButton(gc, this, getWidth() * 3 / 4, getHeight() / 4, " Toggle Sound ", Helper.getDefaultFont(), Color.cyan, Color.black, Color.black); tsftb.addListener(new ComponentListener(){ @Override public void componentActivated(AbstractComponent arg0){ ge.setSoundOn(!ge.isSoundOn()); } }); addComponent(box); addComponent(tsftb); }
@Override public void init(GameContainer container) throws SlickException { this.container = container; this.map = new TiledMap("/home/enzo/newmap.tmx"); SpriteSheet spriteSheet = new SpriteSheet("/home/enzo/SpriteSheetAnim.png", 64, 64); this.animations[0] = loadAnimation(spriteSheet, 0, 1, 0); this.animations[1] = loadAnimation(spriteSheet, 0, 1, 1); this.animations[2] = loadAnimation(spriteSheet, 0, 1, 2); this.animations[3] = loadAnimation(spriteSheet, 0, 1, 3); this.animations[4] = loadAnimation(spriteSheet, 1, 9, 0); this.animations[5] = loadAnimation(spriteSheet, 1, 9, 1); this.animations[6] = loadAnimation(spriteSheet, 1, 9, 2); this.animations[7] = loadAnimation(spriteSheet, 1, 9, 3); Font font = new Font("Verdana", Font.BOLD, 20); UnicodeFont uFont = new UnicodeFont(font, font.getSize(), font.isBold(), font.isItalic()); nameInput = new TextField(container, uFont, 150,20,500,35, new ComponentListener() { public void componentActivated(AbstractComponent source) { message = "Entered1: "+nameInput.getText(); nameInput.setFocus(true); } }); // ComponentListener listener = new ComponentListener(); // TextField nameInput = new TextField(arg0, truetypefont, 150,20,500,35, listener); // // { // public void componentActivated(AbstractComponent source) { // System.out.println("Entered1: "+nameInput.getText()); // } // }); }
@Override public void init(GameContainer container, StateBasedGame game) throws SlickException { // Background image background = new Image("ressources/background/background.jpg"); // Music deadMusic = new Music("ressources/audio/music/gameover.ogg"); // Sound rollover = new Sound("ressources/audio/sound/rollover.ogg"); // Cursor image cursor = new Image("ressources/cursor/hand_cursor.png"); // Color for button when mous is over Color color = new Color(255, 157, 67, 180); // Button "Quitter" Image quitterImage = new Image("ressources/menu/quitter.png"); quitter = new SlickButton(container, quitterImage, WindowGame.BASE_WINDOW_WIDTH / 2 - quitterImage.getWidth() / 2, 500, quitterImage.getWidth(), quitterImage.getHeight(), new ComponentListener() { @Override public void componentActivated(AbstractComponent arg0) { game.enterState(0); } }); quitter.setMouseOverColor(color); quitter.setMouseDownSound(rollover); }
@Override public void close(){ setVisible(false); for(ComponentListener listener : closeListeners){ listener.componentActivated(this); } }
@Override public void init(GameContainer gc) throws SlickException{ super.init(gc); closeButton = new TSFocusButton(gc, this, getX(), getY(), getX() + 16, getY() + 16, new Color(255, 0, 0, 127), Color.black); closeButton.addListener(new ComponentListener(){ @Override public void componentActivated(AbstractComponent source){ instance.close(); } }); }
@Override public void init(GameContainer container, StateBasedGame game) throws SlickException { // Sound rollover = new Sound("ressources/audio/sound/rollover.ogg"); // Background image background = new Image("ressources/background/background.jpg"); // Cursor image cursor = new Image("ressources/cursor/hand_cursor.png"); // Color for button when mous is over Color color = new Color(255, 157, 67, 180); // Button "Quitter" Image quitterImage = new Image("ressources/menu/quitter.png"); quitter = new SlickButton(container, quitterImage, WindowGame.BASE_WINDOW_WIDTH / 2 - quitterImage.getWidth() / 2, 250, quitterImage.getWidth(), quitterImage.getHeight(), new ComponentListener() { @Override public void componentActivated(AbstractComponent arg0) { try { ((LevelState) game.getState(ID_Last)).initialisation(); } catch (SlickException e) { System.err.println("Probl�me pour quitter le level."); e.printStackTrace(); } game.enterState(0); } }); quitter.setMouseOverColor(color); quitter.setMouseDownSound(rollover); // Button "Reprendre" Image reprendreImage = new Image("ressources/menu/reprendre.png"); reprendre = new SlickButton(container, reprendreImage, WindowGame.BASE_WINDOW_WIDTH / 2 - reprendreImage.getWidth() / 2, 400, reprendreImage.getWidth(), reprendreImage.getHeight(), new ComponentListener() { @Override public void componentActivated(AbstractComponent arg0) { game.enterState(ID_Last); } }); reprendre.setMouseOverColor(color); reprendre.setMouseDownSound(rollover); }
public SlickButton(GUIContext container, Image image, int x, int y, int width, int height, ComponentListener listener) { super(container, image, x, y, width, height, listener); }
@Override public void init(GameContainer container, StateBasedGame game) throws SlickException { // Background image background = new Image("ressources/background/background.jpg"); // Cursor image cursor = new Image("ressources/cursor/hand_cursor.png"); // Sounds sound = new Music("ressources/audio/music/home.ogg"); rollover = new Sound("ressources/audio/sound/rollover.ogg"); // Color for button when mous is over Color color = new Color(255, 157, 67, 180); // Button "jouer" Image jouerImage = new Image("ressources/menu/jouer.png"); jouer = new SlickButton(container, jouerImage, WindowGame.BASE_WINDOW_WIDTH / 2 - jouerImage.getWidth() / 2, 250, jouerImage.getWidth(), jouerImage.getHeight(), new ComponentListener() { @Override public void componentActivated(AbstractComponent arg0) { game.enterState(101, new FadeOutTransition(), new FadeInTransition()); } }); jouer.setMouseDownSound(rollover); jouer.setMouseOverColor(color); // Button "niveaux" Image niveauxImage = new Image("ressources/menu/niveaux.png"); niveaux = new SlickButton(container, niveauxImage, WindowGame.BASE_WINDOW_WIDTH / 2 - niveauxImage.getWidth() / 2, 400, niveauxImage.getWidth(), niveauxImage.getHeight(), new ComponentListener() { @Override public void componentActivated(AbstractComponent arg0) { game.enterState(11); } }); niveaux.setMouseDownSound(rollover); niveaux.setMouseOverColor(color); // Button "options" Image optionsImage = new Image("ressources/menu/options.png"); options = new SlickButton(container, optionsImage, WindowGame.BASE_WINDOW_WIDTH / 2 - optionsImage.getWidth() / 2, 550, optionsImage.getWidth(), optionsImage.getHeight(), new ComponentListener() { @Override public void componentActivated(AbstractComponent arg0) { game.enterState(60); } }); options.setMouseDownSound(rollover); options.setMouseOverColor(color); // Button "quitter" Image quitterImage = new Image("ressources/menu/quitter.png"); quitter = new SlickButton(container, quitterImage, WindowGame.BASE_WINDOW_WIDTH / 2 - quitterImage.getWidth() / 2, 700, quitterImage.getWidth(), quitterImage.getHeight(), new ComponentListener() { @Override public void componentActivated(AbstractComponent arg0) { System.exit(0); } }); quitter.setMouseDownSound(rollover); quitter.setMouseOverColor(color); }
public TextButton(GUIContext container, String text, int x, int y, Font font, ComponentListener listener) { this(container, text, x, y, font); addListener(listener); }
@Override public void addCloseListener(ComponentListener listener){ closeListeners.add(listener); }
protected void removeCloseListener(ComponentListener listener){ closeListeners.remove(listener); }
protected Set<ComponentListener> getCloseListeners(){ return closeListeners; }
void addCloseListener(ComponentListener listener);