2016-04-02 10 views
1

JavaFxコードが正しく動作しません。私は1または0のいずれかで移入された10X10のテキスト行列を作成しようとしているので、1と0の2次元配列に似ています。現在MatrixPaneクラスにあるコードをmainに配置するとうまくいきますが、このコードではシーンを設定するだけですが、ペインが追加されたり作成されたりしていないようです。javafxペインが作成されていません

誰かが私を助けることができれば、私はそれを非常に感謝します。

私はいくつかの未使用のものをインポートしたことを認識しています。プログラムの他の部分にも使用しています。

import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.stage.Stage; 
import javafx.scene.layout.FlowPane; 
import javafx.geometry.Point2D; 
import javafx.scene.Node; 
import javafx.scene.layout.Pane; 
import javafx.scene.paint.Color; 
import javafx.scene.shape.Circle; 
import javafx.scene.shape.Line; 
import javafx.scene.text.Text; 
import java.util.Calendar; 
import java.util.GregorianCalendar; 
import javafx.scene.shape.Arc; 
import javafx.scene.control.TextField; 
import javafx.scene.layout.GridPane; 
import javafx.geometry.Pos; 
import javafx.collections.ObservableList; 

public class Button1 extends Application 
{ 
    public void start(Stage primaryStage) 
    { 
     GridPane pane = new GridPane(); 
     MatrixPane Matrix = new MatrixPane(); 
     pane.getChildren().add(Matrix); 

     Scene scene = new Scene(pane, 700, 500); 
     primaryStage.setTitle("1 window "); // Set the stage title 
     primaryStage.setScene(scene); // Place the scene in the stage 
     primaryStage.show(); // Display the stage 
    } 

    public static void main(String[] args) 
    { 
     Application.launch(args); 
    } 

} 


class MatrixPane extends Pane 
{ 
    double HEIGHT = 500; 
    double WIDTH = 200; 
    private GridPane pane1 = new GridPane(); 

    public MatrixPane() 
    { 
    } 

    public void fillmatrix() 
    { 
     for (int i = 0; i < 10; i++) 
     { 
      for (int j = 0; j < 10; j++) 
      { 
       TextField text = new TextField(Integer.toString((int)(Math.random() * 2))); 
       text.setMinWidth(WIDTH/8.0); 
       text.setMaxWidth(WIDTH/10.0); 
       text.setMinHeight(HEIGHT/8.0); 
       text.setMaxHeight(HEIGHT/10.0); 
       this.pane1.add(text, j, i); 
      } 
     } 
    } 
} 

答えて

0

あなたのコードを確認しましたが、あなたはGridPaneを過剰に使用しています。最初に、を継承するMatrixPaneという名前のクラスがありますが、このクラスもプロパティーGridPaneを持っています。最後に、GridPaneをもう一度使用してMatrixPaneを追加します。

シーンがpane1のデータを受信するために起こっているので、ここでfillmatrixだったときに、この属性は値を記憶しているので、私がやったことは組成物を使用することであるが、最初私はstart方法

public void start(Stage primaryStage) { 

    GridPane pane = new GridPane(); 
    MatrixPane Matrix = new MatrixPane(); 
    //pane.getChildren().add(Matrix); 
    Matrix.fillmatrix(); 
    Scene scene = new Scene(Matrix.getPane1(), 700, 500); 
    ... 

を変更と呼ばれる。

は、それから私は、これは動作します

private GridPane pane1 = new GridPane(); 

public MatrixPane() { 
    getChildren().add(pane1); 
} 

MatrixPaneのconstrucorにMatrixPaneするGridPaneを追加Button1.start()

から属性pane1

class MatrixPane { 

    double HEIGHT = 500; 
    double WIDTH = 200; 
    private GridPane pane1 = new GridPane(); 

    public GridPane getPane1() { 
    return pane1; 
    } 
    ... 
+0

もう一度ありがとうございます!それは素晴らしい仕事をした!心から感謝する! – wawiiii

+0

'Pane'から継承したメソッドや' Pane'のインスタンスであるという事実を使用しない場合、 'MatrixPane'を' Pane'に拡張する必要はありません。 'MatrixPane'は' GridPane'自身を拡張し、フィールドを含まないか、 'GridPane'をそれを含むインスタンスの子に追加する必要があります。大括弧をマトリックスに追加する必要があります。また、一種の「レイアウトマネージャー」にする必要がある場合は、 'Object'を直接拡張する必要があります。 – fabian

1

コールfillMatrix();方法のためにMatrixPaneにgetterメソッドを追加します。

+0

ありがとう!それは完璧に働いた! – wawiiii

関連する問題