EventHandler 实现 X 附加到 Pane 并侦听所有 MouseEvents。当然,X 有一个handle()从 JavaFX 应用程序线程接收 MouseEvents的方法。
窗格包含一个矩形。当 Pane 在 Rectangle 上接收到 MouseEvent.MOUSE_CLICK 时,X 会做两件事:
从窗格中移除矩形,然后立即添加另一个矩形(这可能会导致其他事件。
继续进行一些随意的处理
这是问题:
步骤 2 中的处理是否有望在 JavaFX 应用程序线程通过任何进一步的事件提交给 X之前完成handle()?请注意,第 1 步可能会触发其他事件!
只是寻找是或否的回应。你的答案背后的推理也很好!
我应该补充一点,在任何地方都没有涉及任何其他线程,包括在“任意处理”中。
编辑:
示例代码
package bareBonesJavaFXBugExample;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
/**
* An {@link Application} with one {@link Pane} containing one {@link Label}.
* The {@link Label} has a single {@link javafx.event.EventHandler},
* {@link LabelEventHandler} which processes all {@link MouseEvent}s the {@link Label}
* receives.
*
* To trigger the bug, run the application, then spend a second mouse over the
* little label in the upper left hand corner of the screen. You will see output to
* standard I/O. Then, click the label, which will then disppear. Check the I/O for
* Strings ending in debugCounter is 1.
*
* What that String means and how it proves that the JavaFX Application Thread has
* become reentrant is explained in the javadoc of {@link LabelEventHandler}.
*/
public class JavaFXAnomalyBareBonesApplication extends Application
{
public void start(Stage primaryStage)
{
Pane mainPane = new Pane();
mainPane.setMinHeight(800);
mainPane.setMinWidth(800);
Label label = new Label(" this is quite a bug !!!!");
LabelEventHandler labelEventHandler = new LabelEventHandler(mainPane, label);
label.addEventHandler(MouseEvent.ANY, labelEventHandler);
mainPane.getChildren().add(label);
Scene scene = new Scene(mainPane);
primaryStage.setScene(scene);
primaryStage.show();
}
MMMHUHU
相关分类