user interface - Slick2D GUI Button listener -


i'm trying make button in slick extending abstractcomponent:

public class standardbutton extends abstractcomponent {

protected int x; protected int y; protected int width; protected int height; protected string text;  public standardbutton(guicontext container,int x, int y, string text, int width, int height,componentlistener listener) {     super(container);     this.text=text;     setlocation(x, y);     this.width=width;     this.height=height;     addlistener(listener);    }  @override  public void render(guicontext container, graphics g) throws slickexception {     g.setcolor(color.white);     g.setlinewidth(2f);     g.drawrect(x, y, width, height);     g.drawstring(text, x+5, y+(height/2-4));  }  [...] 

and in state:

public class updaterstate extends basicgamestate implements componentlistener { private standardbutton buttonplay;

@override public void init(gamecontainer container, final statebasedgame game)         throws slickexception {         buttonplay=new standardbutton(container,100,100,"graj",60,30,new componentlistener(){              @override             public void componentactivated(abstractcomponent source) {                 state.nextstate(0, game);              }          }); 

but nothing happens. neststate method not run when click button. how schould correctly? want program block in componentactivated method. possible or need chceck if mouse released on button field in update method time buttons?

i recommend take quick peak @ buckys videos give helpful tips on making stuff slick 2d.

http://www.youtube.com/watch?v=axndbqfcd08&feature=share&list=pl22ef3e3752768216

that's link playlist of tutorials. 1 of videos talks making buttons , switching states. luck , hope make amazing program :)


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -