2015-11-01 166 views
0

我從here得到了javaFX中解決rubik的魔方的源代碼。有用於提示對話框,用戶輸入或進行確認作爲代碼:無法提示javaFX中的信息消息或警告消息/

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()和手動輸入的反應,一切工作正常。

回答

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對話框這是有一段時間了。

+0

jdk 1.8 and controlsfx-8.0.5.jar –

+0

這是不夠的信息。 jdk 1.8的哪個更新?如果它是最新的8u66,那麼你的controlsfx版本太舊了。 – mipa

+0

是的,它的8更新65 –