Stas Jaro
Stas Jaro

Reputation: 4885

How do i specify which class to call a method from

When i run the code below, the fireEvent() method is called inside the Slider class instead of the ColorPanel class. How can i make it call the fireEvent() method in the ColorPanel class? (They both extend EventComponent which has the method)

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();
            }
        });
    }
}

Upvotes: 0

Views: 56

Answers (2)

MByD
MByD

Reputation: 137322

You should specify the class like this:

ColorPanel.this.fireEvent();

Upvotes: 0

socha23
socha23

Reputation: 10239

Point the compiler to the right method by changing fireEvent(); to ColorPanel.this.fireEvent();

Upvotes: 2

Related Questions