2010-08-19 54 views

回答

0

ClickEvent s有一个getSource()方法,它包含事件的来源,这很有帮助。

public class NiceLabel { 
    public final Row row; 
    public NiceLabel(Row row, ClickHandler clickHandler) { 
    this.row = row; 
    addClickHandler(clickHandler); 
    } 
} 

... 
// clickHandler has the following: 
public void onClick(ClickEvent event) { 
    ((NiceLabel) event.getSource()).row.moveUp(); 
} 

并以这种方式,你可以添加相同ClickHandlerNiceLabel,而无需创建为每行一个新的。

相关问题