2017-02-27 4 views
0

게이트 및 연결을 드래그하여 논리 회로를 수정하고 시각화 할 수있는 간단한 Java 응용 프로그램을 작성하려고합니다. SceneBuilder를 사용하여 인터페이스를 결합했습니다. 바로 지금, 나는 그들의 적절한 막대에 표시하고 상호 작용에 응답 할 수있는 사용 가능한 기본 논리 게이트를 얻는 데 주저하고 있습니다. 좀 더 정확히 말하자면 GUI 출력 연결을 확인하기 위해 콘솔 출력을 표시하는 하나의 게이트를 얻으려고합니다.SceneBuilder에서 FXB : ImageViews가 실제 앱에 표시되지 않습니다.

내가 겪고있는 가장 큰 문제는 Gate의 ImageViews가 다른 FXML 요소와 함께 가능하면 SceneBuilder에서 제대로 작동하고 반응하지만 어떤 이유로 든 실제 컴파일 된 응용 프로그램에서 표시하지 않기 때문입니다. 그것의 "미리보기"기능.

다른 많은 FXML 요소로 래핑하는 방법을 연습해야했는데, 실제로 이해하지 못했던 것은 분명히 ImageWiew에는 onDragDetected() 메서드가 없기 때문입니다. 텍스트 입력 필드가 SceneBuilder에서 가능하지만 . 의도 한 작업 진행 중 app 레이아웃은 첫 번째 그림의 SceneBuilder에서 직접 볼 수 있습니다. 실제 실행중인 응용 프로그램의 두 번째 응용 프로그램과 비교하십시오.

As seen in SceneBuilder GUI of the running app

아마 관련 코드 :

Main.java

package main; 

    import javafx.application.Application; 
    import javafx.fxml.FXMLLoader; 
    import javafx.scene.Parent; 
    import javafx.scene.Scene; 
    import javafx.stage.Stage; 

    public class Main extends Application { 

     @Override 
     public void start(Stage primaryStage) throws Exception{ 
      Parent root = FXMLLoader.load(getClass().getResource("RootLayout.fxml")); 
      primaryStage.setTitle("Hello World"); 
      primaryStage.setScene(new Scene(root, 640, 450)); 
      primaryStage.show(); 
     } 

     public static void main(String[] args) throws Exception { 
      launch(args); 
     } 
    } 

TheCircuitController.java

package Gates; 

import javafx.fxml.FXML; 
import javafx.fxml.Initializable; 
import javafx.scene.input.MouseEvent; 
import javafx.scene.layout.AnchorPane; 

import java.net.URL; 
import java.util.ArrayList; 
import java.util.ResourceBundle; 


/** 
* The class for holding all the information about gates, connections, and in and out pins in the current circuit 
*/ 
public class TheCircuitController implements Initializable{ 

    @FXML 
    private AnchorPane anchorPaneNAND; 

    //TODO temporarily public, make private later 
    public ArrayList<CircuitElement> allCircuitElements= new ArrayList<CircuitElement>(); 
    public ArrayList<Pin> theCircuitInputPins = new ArrayList<Pin>(); 
    public ArrayList<Pin> theCircuitOutputPins = new ArrayList<Pin>(); 
    ArrayList<Connection> allCircuitConnections = new ArrayList<Connection>(); 
    public ArrayList<Pin> allCircuitGateInputPins = new ArrayList<Pin>(); 
    public ArrayList<Pin> allCircuitGateOutputPins = new ArrayList<Pin>(); 
    public ArrayList<Gate> allCircuitGates = new ArrayList<Gate>(); 

    private InbuiltGateType currentDragGateType; 

    @Override 
    public void initialize(URL fxmlFileLocation, ResourceBundle resources) { 
     // initialize your logic here: all @FXML variables will have been injected 
     anchorPaneNAND.setOnDragDetected(this::handleDragDetectedNAND); 
    } 

    @FXML 
    private void handleDragDetectedNAND(MouseEvent mouseEvent) { 
     System.out.println("drag detected nand!"); 
    } 

//other stuff of the class, unrelated to FXML 
} 

RootLayout.fxml

<?xml version="1.0" encoding="UTF-8"?> 

<?import javafx.geometry.*?> 
<?import javafx.scene.image.*?> 
<?import javafx.scene.control.*?> 
<?import javafx.scene.layout.*?> 

<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="450.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Gates.TheCircuitController"> 
    <children> 
     <MenuBar prefHeight="27.0" prefWidth="562.0"> 
     <menus> 
      <Menu mnemonicParsing="false" text="File"> 
      <items> 
       <MenuItem mnemonicParsing="false" text="Close" /> 
      </items> 
      </Menu> 
      <Menu mnemonicParsing="false" text="Edit"> 
      <items> 
       <MenuItem mnemonicParsing="false" text="Delete" /> 
      </items> 
      </Menu> 
      <Menu mnemonicParsing="false" text="Help"> 
      <items> 
       <MenuItem mnemonicParsing="false" text="About" /> 
      </items> 
      </Menu> 
     </menus> 
     </MenuBar> 
     <SplitPane dividerPositions="0.2413793103448276" prefHeight="402.0" prefWidth="640.0"> 
     <items> 
      <ScrollPane fitToHeight="true" fitToWidth="true" prefHeight="400.0" prefWidth="122.0"> 
       <content> 
        <VBox prefHeight="400.0" prefWidth="208.0" spacing="10.0"> 
        <children> 
         <AnchorPane fx:id="anchorPaneNAND" onDragDetected="#handleDragDetectedNAND"> 
          <children> 
           <ImageView> 
           <image> 
            <Image url="@../../resources/100px-NAND_ANSI.svg.png" /> 
           </image> 
           </ImageView> 
          </children> 
         </AnchorPane> 
         <ImageView> 
          <image> 
           <Image url="@../../resources/100px-NOT_ANSI.svg.png" /> 
          </image> 
         </ImageView> 
         <ImageView> 
          <image> 
           <Image url="@../../resources/100px-AND_ANSI.svg.png" /> 
          </image> 
         </ImageView> 
         <ImageView> 
          <image> 
           <Image url="@../../resources/OR_ANSI.svg.png" /> 
          </image> 
         </ImageView> 
         <ImageView> 
          <image> 
           <Image url="@../../resources/100px-NOR_ANSI.svg.png" /> 
          </image> 
         </ImageView> 
         <ImageView> 
          <image> 
           <Image url="@../../resources/100px-XOR_ANSI.svg.png" /> 
          </image> 
         </ImageView> 
         <ImageView> 
          <image> 
           <Image url="@../../resources/100px-XNOR_ANSI.svg.png" /> 
          </image> 
         </ImageView> 
        </children> 
        <padding> 
         <Insets left="20.0" right="20.0" /> 
        </padding></VBox> 
       </content></ScrollPane> 
      <ScrollPane prefHeight="400.0" prefWidth="406.0" /> 
     </items> 
     </SplitPane> 
    </children> 
</VBox> 

나는 이렇게 알고 있어야합니다

왜 그 게이트 (또는 적어도 하나의) 의도 한대로 표시되지는? 그리고 ScrollPane에는 SceneBuilder와 마찬가지로 슬라이더가 표시되지 않는 이유는 무엇입니까? 그 성문이 올바르게 나타나고 상호 작용하도록하기 위해서는 무엇을 다르게 설정하거나 흔들어야합니까?

+0

장면 그래프가 올바르게 빌드되었는지 확인하는 가장 좋은 방법은 http://fxexperience.com/scenic-view/를 사용하는 것입니다. ScrollPane과 VBox가있는 경우 높이 값을 확인하십시오. 또한 애플리케이션을 작성한 방법에 따라 다릅니다. 이미지가 모자이크 된 후 올바른 위치에 있지 않을 수도 있습니다. – Westranger

답변

0

무작위로 약간의 고생을 한 후에 해결책을 찾았습니다.

먼저, View->Show Sample Controller Skeleton을 조사했습니다. 거기에서, 메서드에는 어떤 수정자가 없지만, 광산에는 private이 있었고, 튜토리얼이나 다른 튜토리얼에서 일찍 복사되었다. 수정자를 제거하고 이제 응용 프로그램이 작동합니다. 이유가 무엇인지 설명하도록 신경 쓰는 사람이 있다면 (나는 생각할 시간이없고, 연구 할 시간이없고, 마감일이 빨리 다가오고있다.)이 대답의 가치는 상당히 높아질 것이다.

관련 문제