Ciao a tutti, non riesco a capire perchè mi dà errore in questo codice alla dichiarazione dell'EventHandler:
codice:
package esercizi.da.slide;
import java.awt.event.KeyEvent;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.TilePane;
import javafx.stage.Stage;
public class Keyboard1 extends Application {
int counter=0;
@Override
public void start(Stage stage) {
TilePane box=new TilePane();
box.setHgap(50);
final Button b1=new Button("Uno");
final Button b2=new Button("Due");
box.getChildren().addAll(b1,b2);
EventHandler<KeyEvent> keyEventHandler =new EventHandler<KeyEvent>() {
@Override
public void handle(ActionEvent keyEvent) {
if (keyEvent.getCode() == KeyCode.U) {
b1.fireEvent(new ActionEvent());
System.out.println(keyEvent.getSource()
+" => "+keyEvent.getTarget());
}
}
};
Scene scene = new Scene(box, 400, 300);
b1.addEventHandler(KeyEvent.KEY_PRESSED, keyEventHandler);
stage.setTitle("My JavaFX Application");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}