N
N
Noortvel2016-10-29 16:22:59
Java
Noortvel, 2016-10-29 16:22:59

Why doesn't adding an EventHandler from this (error) work?

Why doesn't this work? (gives an error)

Class UIItem implements EventHandler<MouseEvent>{
    public  <E extends Event> void addEventHandler(EventType<E> eventType){
            treeItem.addEventHandler(eventType, this);
    }
    @Override
    public void handle(MouseEvent mouseEvent) {
        System.out.println("EVENT");
    }
}

And it doesn't work (doesn't display "EVENT")
Class UIItem implements EventHandler<MouseEvent>{
    public  <E extends Event> void addEventHandler(EventType<E> eventType){
            treeItem.addEventHandler(eventType, (EventHandler<E>) this);

    }
    @Override
    public void handle(MouseEvent mouseEvent) {
        System.out.println("EVENT");
    }
}

PS Problem Solving
Class UIItem implements EventHandler<MouseEvent>{
    public  <E extends Event> void addEventHandler(EventType<E> eventType){
            treeItem.getValue().addEventHandler(eventType, (EventHandler<E>) this);

    }
    @Override
    public void handle(MouseEvent mouseEvent) {
        System.out.println("EVENT");
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question