たとえば、Polylineオブジェクトを作成するメソッドを記述したクラスがあります。どうすればいいですか?solution.setTranslateY(315)、javafxウィンドウでポリラインを下にシフトします。メソッドのコードを明示的に編集しなくても、メソッド内の何かを移動する方法はありますか?
public Polyline getSolution()
{
Polyline solution = new Polyline();
solution.setStrokeWidth(3);
for (int i = 0; i < coordinates; i = i + 2)
solution.getPoints().addAll(puzzle[i], puzzle[i + 1]);
solution.setTranslateY(315);
//translates this solution farther down the display window
return solution;
}
あなたが見ることができるように、私はグループでそれを入れて、その後、私のプログラムのシーンにそのグループを追加することによって作成されたオブジェクト上でこの「getSolution()」メソッドを実装します。
public void start(Stage primaryStage) throws FileNotFoundException
{
Scanner input = new Scanner(System.in);
System.out.println("Enter the name of the input file: ");
String fileName = input.nextLine();
ConnectTheDotsPuzzle heart = new ConnectTheDotsPuzzle(fileName);
// When the user inputs the file, it gets sent to the constructor
Line blueLine = new Line(0, 300, 500, 300);
//line between puzzle and solution
blueLine.setStroke(Color.BLUE);
blueLine.setStrokeWidth(3);
Text solutionText = new Text(20, 335, "Solution:");
solutionText.setFont(Font.font("Times", FontWeight.BOLD, 24));
Group group = new Group(heart.getPuzzle(), heart.getSolution(),
blueLine, solutionText);
// grouping everything together to put in the scene
Scene scene = new Scene(group, 500,
300);
primaryStage.setTitle("Connect the Dots");
primaryStage.setScene(scene);
primaryStage.show();
primaryStage.setOnCloseRequest(e -> System.exit(0));
}
私の質問は:私は私が作成した最初の方法で私のポリラインオブジェクトを変換する必要がないようにする方法はありますか?私はどのように私の開始方法でそれをシフトすることができますか?私はこれを複数のオブジェクトにしたいと思っていて、いつもそれが315になることを望んでいないのであれば、私のメソッドで定数シフトにするのではなく、私の開始メソッドでどのように変更できるのだろうかと思っていました。
ありがとうございました!私は、私のgetSolutionメソッドがPolylineオブジェクトを作成したという事実についても考えていませんでした。これはまさに私が探していたものです。 – brnn