這是你想要的先生 - 這是它的外觀
![enter image description here](https://i.stack.imgur.com/s9ZFF.png)
package application;
import java.util.Random;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.HLineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
VBox root = new VBox(10);
root.setAlignment(Pos.CENTER);
root.getChildren().addAll(getLine(10,30),getLine(10,30),getLine(10,30),
getLine(10,30),getLine(10,30),getLine(10,30),
getLine(10,30),getLine(10,30),getLine(10,30),getLine(10,30),
getLine(10,30),getLine(10,30),getLine(10,30));
Scene scene = new Scene(root, 400, 400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
private Node getLine(int ponts,int pontLength){
HBox root = new HBox(-1);
root.setAlignment(Pos.CENTER);
Random r = new Random();
while(ponts !=0){
Path p1 = new Path();
p1.getElements().addAll(new MoveTo(), new HLineTo(pontLength));
p1.setStroke(Color.rgb(r.nextInt(255), r.nextInt(255), r.nextInt(255)));
root.getChildren().add(p1);
ponts--;
}
return root;
}
@Override
public void stop() throws Exception {
// TODO Auto-generated method stub
super.stop();
}
public static void main(String[] args) {
launch(args);
}
}
你能後的代碼,而不是代碼的截圖?首先,您不能從屏幕截圖中複製和粘貼,而對於另一個屏幕截圖則不完整。 –
我以爲我把這段代碼連接起來,這就是爲什麼我沒有發佈它,現在我要感謝通知先生。@ James_D – Elltz
這只是一個容器中的多行,它對我來說不夠好。我希望這些線可以通過像折線中的線段一樣的方法進行連接,並且可以對它們使用strokeLineJoin。我只是不明白爲什麼我不可能將每一行都視爲單一形狀,並將其設置爲多段線中的不同顏色,這似乎很自然。 – ezechiel