2013-07-31 71 views
0

我試圖通過擴展AbstractComponent使在光滑的按鈕:Slick2D GUI按鈕偵聽

公共類StandardButton擴展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)); 

} 
[...] 

在我的狀態:

公共類UpdaterState擴展BasicGameState實現了ComponentListener私有標準按鈕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); 

      } 

     }); 

但沒有任何反應。當我點擊我的按鈕時,我的nestState方法不運行。我該如何做到這一點?我只想讓我的程序在componentActivated方法中進行阻塞。這是可能的,或者我只是需要chceck,如果鼠標是在所有按鈕的更新方法的按鈕字段上釋放的所有時間?

回答