Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package jfxtn;
- import java.util.Random;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.geometry.VPos;
- import javafx.scene.Group;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.input.KeyEvent;
- import javafx.scene.layout.StackPane;
- import javafx.scene.paint.Color;
- import javafx.scene.text.Font;
- import javafx.scene.text.Text;
- import javafx.stage.Stage;
- /**
- *
- * bem10jfx.blogspot.com
- * numagrndeviagem.blogspot.com
- * knb jfx.blogspot.com
- */
- public class Jfxtn extends Application {
- Group go=new Group();
- final Text txletra=new Text("X");
- final Random c=new Random(System.currentTimeMillis());
- final Random o=new Random(System.currentTimeMillis());
- final Random r=new Random(System.currentTimeMillis());
- Text txCont=new Text("letra-");
- int i;
- @Override
- public void start(Stage stage) {
- i=1;
- final Scene scene=new Scene(go,400,400,Color.ALICEBLUE);
- stage.setScene(scene);
- txletra.setTextOrigin(VPos.TOP);
- go.getChildren().add(txletra);
- txletra.setFont(Font.font(STYLESHEET_MODENA, 96));
- txletra.setLayoutX(7);
- txletra.layoutXProperty().bind(stage.widthProperty().divide(2));
- txletra.layoutYProperty().bind(stage.heightProperty().divide(2));
- //expressao lmbda
- scene.setOnKeyPressed((KeyEvent event) -> {
- System.out.println(""+event.getText());
- txletra.setText(event.getText());
- // System.out.println("entrada random de cor"+c.nextInt(203)+o.nextInt(201)+r.nextInt(201));
- int vlc=c.nextInt(203);
- int vlo=o.nextInt(201);
- int vlr=r.nextInt(201);
- // System.out.println("entrada random de cor"+vlc+","+vlo+","+vlr+",");
- scene.setFill(Color.rgb(vlc,vlo,vlr));
- txletra.setFill(Color.rgb(vlr,vlo,vlc));
- txCont.setFill(Color.rgb(vlr,vlo,vlc));
- Text txDigitos=new Text();
- i++;
- txCont.setText("letras -"+i);
- txDigitos.setText("-"+event.getText());
- txDigitos.layoutXProperty().bind(stage.widthProperty().subtract(stage.widthProperty()).add(13).multiply(i));
- txDigitos.layoutYProperty().bind(stage.heightProperty().subtract(80));
- txDigitos.setTextOrigin(VPos.TOP);
- txDigitos.setFont(Font.font(STYLESHEET_MODENA, 25));
- txDigitos.setFill(Color.rgb(vlr,vlc,vlo));
- go.getChildren().addAll(txDigitos);
- });
- txCont.setLayoutX(25);
- txCont.layoutYProperty().bind(stage.heightProperty().subtract(96));
- txCont.setTextOrigin(VPos.TOP);
- txCont.setFont(Font.font(STYLESHEET_MODENA, 25));
- go.getChildren().addAll(txCont);
- stage.show();
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment