当我运行下面的代码时,在Slider类而不是ColorPanel类中调用fireEvent()
方法。如何让它调用ColorPanel类中的fireEvent()
方法? (它们都扩展了具有该方法的EventComponent)
public class ColorPanel extends EventComponent<ColorChangeListener> {
public ColorPanel() {
...
add(new ValueSlider());
}
.................more Code
@Override
protected void fireEvent() {
for (ColorChangeListener l : listeners)
l.colorChanged(color);
}
private class ValueSlider extends Slider {
public ValueSlider() {
super(0, 200, 200, 200);
this.x = 10;
this.y = 220;
addListener(new ValueChangeListener() {
@Override
public void valueChanged(int value) {
colorCircle.setValue(value / 200f);
color = colorCircle.getSelectedColor();
fireEvent();
}
});
}
}
答案 0 :(得分:2)
将fireEvent();
更改为ColorPanel.this.fireEvent();
答案 1 :(得分:0)
您应该像这样指定类:
ColorPanel.this.fireEvent();