Demo entry 6760823

Java

   

Submitted by anonymous on Sep 18, 2018 at 11:17
Language: Java. Code size: 2.2 kB.

import javafx.application.Application; 
import javafx.scene.Group; 
import javafx.scene.Scene; 

import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;

import javafx.scene.layout.HBox;
import javafx.scene.layout.BorderPane;

import javafx.stage.Stage;

import javafx.scene.paint.Color;

import javafx.scene.text.Text;
import javafx.scene.text.Font;

import java.util.Random;

public class TestBorderPane extends Application { 
   @Override     
   public void start(Stage primaryStage) throws Exception {            

      //Création d'un objet de type Groupe --> Scene 
      Group group = new Group(); 

      Random rand = new Random();
      
      //Création de la Scene en lui passant le noeud racine
      //ainsi que la largeur et la hauteur
      Scene scene = new Scene(group ,800, 600);

      // création du gestionnaire BorderPane
      BorderPane bp = new BorderPane();
      

      Rectangle r1 = new Rectangle(50,50);
      Rectangle r2 = new Rectangle(20,20);
      Rectangle r3 = new Rectangle(100,100);
      Rectangle r4 = new Rectangle(80,80);

      Color c = Color.rgb(rand.nextInt(255),
			  rand.nextInt(255),
			  rand.nextInt(255));
      r1.setFill(c);
      c = Color.rgb(rand.nextInt(255),
			  rand.nextInt(255),
			  rand.nextInt(255));
      r2.setFill(c);
      c = Color.rgb(rand.nextInt(255),
			  rand.nextInt(255),
			  rand.nextInt(255));
      r3.setFill(c);
      c = Color.rgb(rand.nextInt(255),
			  rand.nextInt(255),
			  rand.nextInt(255));
      r4.setFill(c);

      Text t = new Text("Test BorderPane");
      t.setFont(new Font(24));
      
      bp.setCenter(r1);
      bp.setTop(t);
      bp.setLeft(r2);
      bp.setRight(r3);
      bp.setBottom(r4);

      group.getChildren().add(bp);
       
      //On remplit la Scene d'une couleur
      //scene.setFill(lg);  
      
      //Ajout d'un titre à la fenêtre --> Stage
      primaryStage.setTitle("Gestionnaire BorderPane"); 
   
      //On ajoute la Scene au stage --> Stage
      primaryStage.setScene(scene); 
       
      //On affiche le stage
      primaryStage.show(); 
   }    
   public static void main(String args[]){          
      launch(args);     
   }         
} 

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).