Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package slick2dbutton;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import org.newdawn.slick.AppGameContainer;
- import org.newdawn.slick.BasicGame;
- import org.newdawn.slick.GameContainer;
- import org.newdawn.slick.Graphics;
- import org.newdawn.slick.Image;
- import org.newdawn.slick.SlickException;
- import org.newdawn.slick.gui.AbstractComponent;
- import org.newdawn.slick.gui.ComponentListener;
- import org.newdawn.slick.gui.GUIContext;
- import org.newdawn.slick.gui.MouseOverArea;
- public class Slick2DButton extends BasicGame {
- Button button;
- public Slick2DButton(String title) {
- super(title);
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- AppGameContainer game;
- try {
- game = new AppGameContainer(new Slick2DButton("Slick2DButton Test"));
- game.setMaximumLogicUpdateInterval(60);
- game.setDisplayMode(640, 480, false);
- game.setTargetFrameRate(60);
- game.setAlwaysRender(true);
- game.setVSync(true);
- game.setShowFPS(false);
- game.start();
- } catch (SlickException ex) {
- Logger.getLogger(Slick2DButton.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- @Override
- public void init(GameContainer container) throws SlickException {
- button = new Button(container, new Image("res/bunsen burner #1.png"), 50, 50, new Slick2DButton.Listener());
- button.setMouseOverImage(new Image("res/bunsen burner #2.png"));
- button.inputStarted();
- }
- @Override
- public void update(GameContainer container, int delta) throws SlickException {
- }
- @Override
- public void render(GameContainer container, Graphics g) throws SlickException {
- button.render(container, g);
- }
- public class Listener implements ComponentListener {
- @Override
- public void componentActivated(AbstractComponent source) {
- System.out.println("Source: " + source);
- }
- }
- public class Button extends MouseOverArea {
- public Button(GUIContext container, Image im, int x, int y, ComponentListener listener) {
- super(container, im, x, y, listener);
- }
- @Override
- public void mousePressed(int button, int mx, int my) {
- super.mousePressed(button, mx, my);
- // this.notifyListeners();
- System.out.println("Button: " + button);
- System.out.println("");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement