我从here获得了在javaFX中解决rubik&x cube的源代码。有一个用于提示用户输入或确认对话框的代码:
Button bSeq = new Button("Sequence");
bSeq.setOnAction(e -> {
String response;
if (moves.getNumMoves() > 0) {
response =
Dialogs.create()
.owner(stage)
.title("Warning Dialog")
.masthead("Loading a Sequence").lightweight()
.message("Add a valid sequence of movements:\n(previous movements will be discarded)")
.showTextInput(moves.getSequence());
} else {
response = Dialogs.create()
.owner(stage)
.title("Information Dialog")
.masthead("Loading a Sequence").lightweight()
.message("Add a valid sequence of movements")
.showTextInput();
}
System.out.println("r: " + response);
if (response != null && !response.isEmpty()) {
rubik.doReset();
rubik.doSequence(response.trim());
}
});
和确认对话框:
Button bSc = new Button("Scramble");
bSc.setOnAction(e -> {
if (moves.getNumMoves() > 0) {
Action response = Dialogs.create()
.owner(stage)
.title("Warning Dialog")
.masthead("Scramble Cube")
.message("You will lose all your previous movements. Do you want to continue?")
.showConfirm();
if (response == Dialog.Actions.YES) {
rubik.doReset();
doScramble();
}
} else {
doScramble();
}
});
但是点击那个bSeq和bSc按钮没有对话框得到提示,我得到的例外是:
java.lang.NoSuchMethodError: com.sun.javafx.scene.traversal.TraversalEngine.<init>(Ljavafx/scene/Parent;Z)V
at org.controlsfx.control.ButtonBar$2.<init>(ButtonBar.java:413)
at org.controlsfx.control.ButtonBar.<init>(ButtonBar.java:413)
at org.controlsfx.control.ButtonBar.<init>(ButtonBar.java:356)
at org.controlsfx.dialog.Dialog.createButtonPanel(Dialog.java:978)
at org.controlsfx.dialog.Dialog.createCenterPanel(Dialog.java:973)
at org.controlsfx.dialog.Dialog.buildDialogContent(Dialog.java:894)
at org.controlsfx.dialog.Dialog.show(Dialog.java:321)
at org.controlsfx.dialog.Dialogs.showTextInput(Dialogs.java:537)
at org.controlsfx.dialog.Dialogs.showTextInput(Dialogs.java:545)
at com.jpl.games.RubikFX.lambda$start$5(RubikFX.java:125)
at com.jpl.games.RubikFX$$Lambda$95/2071613919.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
r: null
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8390)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3758)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3486)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2495)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:350)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:275)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$350(GlassViewEventHandler.java:385)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$$Lambda$165/13695958.get(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:404)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:384)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:927)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101)
at com.sun.glass.ui.win.WinApplication$$Lambda$36/1963387170.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
如果我删除Diaog.create()
并手动输入回复,一切正常。
答案 0 :(得分:1)
您还没有告诉我们您正在使用哪个JDK和ControlsFX版本,但我猜您已经遇到了这个问题。
http://fxexperience.com/2015/08/controlsfx-and-javafx-8u60/
顺便说一下,当前的快照链接现在是
https://oss.sonatype.org/content/repositories/snapshots/org/controlsfx/controlsfx/8.40.11-SNAPSHOT/
您也可以尝试将代码转换为标准JavaFX对话框,这些对话框现在已有一段时间了。