I copied the code in the lambda expression from my text book, except I swapped text for circle. I'm not sure why it is having issues with getX and getY. Any help would be greatly appreciated.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.shape.Circle;
import javafx.scene.layout.StackPane;
public class MoveUsingKeys extends Application {
@Override
public void start(Stage primaryStage)
{
StackPane pane = new StackPane();
Circle circle = new Circle(150, 150, 25);
pane.getChildren().add(circle);
circle.setOnKeyPressed(e -> {
switch(e.getCode()){
case DOWN: circle.setY(circle.getY() - 10); break;
case UP: circle.setY(circle.getY() + 10); break;
case LEFT: circle.setX(circle.getX() - 10); break;
case RIGHT: circle.setX(circle.getX() + 10); break;
}
});
Scene scene = new Scene(pane, 300, 300);
primaryStage.setTitle("Exercise15_11");
primaryStage.setScene(scene);
primaryStage.show();
circle.requestFocus();
}
public static void main(String[] args)
{
Application.launch(args);
}
}