packageapplication;importjava.util.Random;importjavafx.application.Application;importjavafx.geometry.Pos;importjavafx.scene.Node;importjavafx.scene.Parent;importjavafx.scene.Scene;importjavafx.scene.layout.HBox;importjavafx.scene.layout.VBox;importjavafx.scene.paint.Color;importjavafx.scene.shape.HLineTo;importjavafx.scene.shape.MoveTo;importjavafx.scene.shape.Path;importjavafx.stage.Stage;publicclassMultiColoredLinePointsextendsApplication{@Overridepublicvoidstart(StageprimaryStage){try{VBoxroot=newVBox(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));Scenescene=newScene(root,400,400);scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());primaryStage.setScene(scene);primaryStage.show();}catch(Exceptione){e.printStackTrace();}}privateNodegetLine(intponts,intpontLength){HBoxroot=newHBox(-1);root.setAlignment(Pos.CENTER);Randomr=newRandom();while(ponts!=0){Pathp1=newPath();p1.getElements().addAll(newMoveTo(),newHLineTo(pontLength));p1.setStroke(Color.rgb(r.nextInt(255),r.nextInt(255),r.nextInt(255)));root.getChildren().add(p1);ponts--;}returnroot;}@Overridepublicvoidstop()throwsException{// TODO Auto-generated method stubsuper.stop();System.exit(0);}publicstaticvoidmain(String[]args){launch(args);}}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.