Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. package slick2dbutton;
  2.  
  3. import java.util.logging.Level;
  4. import java.util.logging.Logger;
  5. import org.newdawn.slick.AppGameContainer;
  6. import org.newdawn.slick.BasicGame;
  7. import org.newdawn.slick.GameContainer;
  8. import org.newdawn.slick.Graphics;
  9. import org.newdawn.slick.Image;
  10. import org.newdawn.slick.SlickException;
  11. import org.newdawn.slick.gui.AbstractComponent;
  12. import org.newdawn.slick.gui.ComponentListener;
  13. import org.newdawn.slick.gui.GUIContext;
  14. import org.newdawn.slick.gui.MouseOverArea;
  15.  
  16. public class Slick2DButton extends BasicGame {
  17.  
  18. Button button;
  19.  
  20. public Slick2DButton(String title) {
  21. super(title);
  22. }
  23.  
  24. /**
  25. * @param args the command line arguments
  26. */
  27. public static void main(String[] args) {
  28. AppGameContainer game;
  29. try {
  30. game = new AppGameContainer(new Slick2DButton("Slick2DButton Test"));
  31. game.setMaximumLogicUpdateInterval(60);
  32. game.setDisplayMode(640, 480, false);
  33. game.setTargetFrameRate(60);
  34. game.setAlwaysRender(true);
  35. game.setVSync(true);
  36. game.setShowFPS(false);
  37. game.start();
  38. } catch (SlickException ex) {
  39. Logger.getLogger(Slick2DButton.class.getName()).log(Level.SEVERE, null, ex);
  40. }
  41. }
  42.  
  43. @Override
  44. public void init(GameContainer container) throws SlickException {
  45. button = new Button(container, new Image("res/bunsen burner #1.png"), 50, 50, new Slick2DButton.Listener());
  46. button.setMouseOverImage(new Image("res/bunsen burner #2.png"));
  47. button.inputStarted();
  48. }
  49.  
  50. @Override
  51. public void update(GameContainer container, int delta) throws SlickException {
  52. }
  53.  
  54. @Override
  55. public void render(GameContainer container, Graphics g) throws SlickException {
  56. button.render(container, g);
  57. }
  58.  
  59. public class Listener implements ComponentListener {
  60.  
  61. @Override
  62. public void componentActivated(AbstractComponent source) {
  63. System.out.println("Source: " + source);
  64. }
  65. }
  66.  
  67. public class Button extends MouseOverArea {
  68.  
  69. public Button(GUIContext container, Image im, int x, int y, ComponentListener listener) {
  70. super(container, im, x, y, listener);
  71. }
  72.  
  73. @Override
  74. public void mousePressed(int button, int mx, int my) {
  75. super.mousePressed(button, mx, my);
  76. // this.notifyListeners();
  77. System.out.println("Button: " + button);
  78. System.out.println("");
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement