java - Netbeans IDE 在创建新的 ActionTimer、ChangeListener 后“停止工作”
问题描述
@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();
}
我正在学习 mooc.fi Java 课程,现在在第 14 部分,并且有一个我想尝试的示例代码。这是代码有问题的部分。当我将它粘贴到main 方法上方的DiceRolling
类(即 extends )中时,IDE 将失去其所有功能。Application
这意味着Ctrl+Space在代码中无处显示任何建议,如果我用鼠标选择部分代码我无法Ctrl+X它,停止检查代码是否有错误(谈论红色下划线),它只是整体停止检查代码。我可以将原因缩小到new ActionTimer
代码的一部分。只有在第一个大括号被写入之后才会出现问题。
我之前遇到过这个问题,当时我ChangeListener
在 lambda 表达式中创建了一个新的,第一个大括号也导致了这个问题。我不知道它为什么会发生,或者它是否有意义或者它只是一个错误。
解决方案
推荐阅读
- c# - 在 C# .NET Controller 类中使用 React 表单提交
- mqtt - Mosquitto brocker 仅用于本地主机?
- tensorflow - 如何在 Tensorflow CNN 模型中修剪权重(无需将模型迁移到 Keras)
- excel - 命名范围以隐藏/显示列
- android - 未解决的参考,在错误的测试范围内 - Android Studio 3.5
- python - 表单对 django 无效,为什么
- unity3d - Platform Grills Scroll Animation - 2D 游戏
- c# - 如何配置 ASP.NET MVC 以使用 ADFS oAuth 作为授权服务器?
- reactjs - reactstrap 轮播图像显示问题(过去的帖子没有帮助)
- excel - 使用 VBA 代码将 Excel 中的数据验证(下拉列表)转换为整列