Snippets

Terah MultiColoredLinePoints

Created by Terah
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 MultiColoredLinePoints 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();
		System.exit(0);
	}

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

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.