tags:

views:

334

answers:

1

New to java and Android -- .Net background.

I cannot figure out how to create event, listeners, and dispatch events. I am building a bowling score keeper class in which there is a game which own frames. I do not want the frames to have knowledge of its parent but insteat want the frame to raise events (frameScored, firstBallRolled, etc)

Here is what I've done so far (is this right so far? How do I raise events out of the frame class). I got most of this from http://stackoverflow.com/questions/1204982 but the 'listenerList' object isn't initialized to anything and I don't know what it should be.

public interface IFrameListener {
    // event dispatch methods
    void FirstBallRolled(Frame frame, byte pinsDownedFirstBall);
    void SecondBallRolled(Frame frame, byte pinsDownedFirstBall, byte pinsDownedSecondBall);
    void FrameScored(Frame frame);
    void FrameAdvanced();
}

import java.util.EventObject;

class FrameScoredEvent extends EventObject {
    public FrameScoredEvent(Object source) {
        super(source);
    }
}

interface FrameListener {
    // event dispatch methods
    void FirstBallRolled(Frame frame, byte pinsDownedFirstBall);

    void SecondBallRolled(Frame frame, byte pinsDownedFirstBall,
            byte pinsDownedSecondBall);

    void FrameScored(Frame frame);

    void FrameAdvanced();
}

class Game implements FrameListener {

    @Override
    public void FirstBallRolled(Frame frame, byte pinsDownedFirstBall) {
        // TODO Auto-generated method stub

    }

    @Override
    public void FrameAdvanced() {
        // TODO Auto-generated method stub

    }

    @Override
    public void FrameScored(Frame frame) {
        // TODO Auto-generated method stub

    }

    @Override
    public void SecondBallRolled(Frame frame, byte pinsDownedFirstBall,
            byte pinsDownedSecondBall) {
        // TODO Auto-generated method stub

    }

Here's the vb.net code I'm trying to duplicate

Please help an unlearned vb.net developer who only knows:

Private WithEvents _CurrentFrame As Frame
...
    Private Sub _CurrentFrame_ScoreFrame(ByVal Score As Int16) Handles      _CurrentFrame.ScoreFrame
End Sub
A: 

Perhaps my answer won't be very helpful, but, since your Game class implements FrameListener interface, you should add it to the listenerList.

kohomologie