The following instance repeats a line of text in a different color and direction.
This example code is as follows:
import java.util.random; import javafx.application.application; import javafx.scene.group; import javafx.scene.scene; import javafx.scene.paint.color; import javafx.scene.text.text; import javafx.stage.stage; public class colortext extends application { @Override // override the start method in the Application class Public void start (stage primarystage) { group root = new group (); scene scene = new scene (Root, 300, 250, color.white); Random rand = new random (System.currenttimemillis ()); for (int i=0; i<100; i++) { int x = Rand.nextint ((int) scene.getwidth ()); int y = rand.nextint ((int) scene.getheight ()); int red = rand.nextint (255); int green = rand.nextint (255); int blue = rand.nextint (255); text text = new text (x,y, "javafx programing fengbin"); int rot = rand.nextint (; ) text.setfill (Color.rgb (red,green, blue, .99)); &nbSp; text.setrotate (Rot); Root.getchildren (). Add (text); } primarystage.settitle ("Colortext"); primarystage.setscene (scene); primarystage.show (); }}
The results of the operation are as follows:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/4E/72/wKioL1RgmD6iecPPAAHGpDLPbbM637.jpg "title=" Qq20141110171904.png "alt=" Wkiol1rgmd6iecppaahgpdlpbbm637.jpg "/>
Description
1.since The initial release of the JDK, we can use the java.util.Random class to generate random numbers. In JDK1.2 ,the Random class has a method named nextint () :
public int Nextint (int n)
Given a parameter n,nextint (n) returns a random number greater than or equal to 0 less than n , i.e.: 0<= nextint (n) < n .
2. System.currenttimemillis () It returns the number of milliseconds that have elapsed since UTC 1970 1 months , 1 days, and midnight.
3. The seed used by the new Random () construction method is the current system.currenttimemillis () ,so the above code:Random rand = new Random (System.currenttimemillis ()); can be shortened to Random rand = new Random ();
4. Group root = new Group (); can be changed into Pane Pane = new Pane ();
This article is from the "Fengbin Technology blog" blog, make sure to keep this source http://fengbin8606.blog.51cto.com/8840305/1575124
Fengbin: JavaFX Instance (12) "Colortext"