Netbeans IDE "stops working" apprently after creating new ActionTimer, ChangeListener

Viewed 14
@Override
public void start(Stage stage) {
    // The class Random is used to randomize the dice rolls
    Random random = new Random();

    NumberAxis xAxis = new NumberAxis();
    // y-axes represents the average of the rolls. The average is always between [1-6]
    NumberAxis yAxis = new NumberAxis(1, 6, 1);

    LineChart<Number, Number> lineChart = new LineChart<>(xAxis, yAxis);
    // removing elements of the chart, e.g. circles on points
    lineChart.setLegendVisible(false);
    lineChart.setAnimated(false);
    lineChart.setCreateSymbols(false);

    // we create a variable representing the data and add it to the chart
    XYChart.Series average = new XYChart.Series();
    lineChart.getData().add(average);

    new AnimationTimer() {
        private long previous;
        private long sum;
        private long count;

        @Override
        public void handle(long current) {
            if (current - previous < 100_000_000L) {
                return;
            }

            previous = current;

            // roll the dice
            int number = random.nextInt(6) + 1;

            // we grow the sum and increment the count
            sum += number;
            count++;

            // we add a new data point to the chart
            average.getData().add(new XYChart.Data(count, 1.0 * sum / count));
        }
    }.start();

    Scene scene = new Scene(lineChart, 400, 300);
    stage.setScene(scene);
    stage.show();
}

I am doing the mooc.fi Java course, right now at part 14, and there was an example code I wanted to try out. This is the problematic part of the code. When I paste this into the DiceRolling class (that extends Application) above the main method, the IDE loses all its functionalities. What it means is that Ctrl+Space shows no suggestion nowhere in the code, if I select part of the code with mouse I cannot Ctrl+X it out, stops checking if the code has mistakes in it (talking about the red underline), and it just overall stops checking the code. I could narrow the reason down to the new ActionTimer part of the code. The problem occurs only after the first curly bracket is written there.

I have experienced this problem earlier, at that time I was creating a new ChangeListener inside a lambda expression and the first curly bracket caused the problem there too. I have no idea why it happens, or if it has a meaning or it's just a bug.

0 Answers
Related