Guest User

scene_Keyevents

a guest
Jul 12th, 2015
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.07 KB | None | 0 0
  1.  
  2. package jfxtn;
  3.  
  4. import java.util.Random;
  5. import javafx.application.Application;
  6. import javafx.event.ActionEvent;
  7. import javafx.event.EventHandler;
  8. import javafx.geometry.VPos;
  9. import javafx.scene.Group;
  10. import javafx.scene.Scene;
  11. import javafx.scene.control.Button;
  12. import javafx.scene.input.KeyEvent;
  13. import javafx.scene.layout.StackPane;
  14. import javafx.scene.paint.Color;
  15. import javafx.scene.text.Font;
  16. import javafx.scene.text.Text;
  17. import javafx.stage.Stage;
  18.  
  19. /**
  20.  *
  21.  *  bem10jfx.blogspot.com
  22.  * numagrndeviagem.blogspot.com
  23.  * knb jfx.blogspot.com
  24.  */
  25. public class Jfxtn extends Application {
  26.     Group go=new Group();
  27.       final  Text txletra=new Text("X");
  28.        final  Random c=new Random(System.currentTimeMillis());
  29.            final Random o=new Random(System.currentTimeMillis());
  30.            final Random r=new Random(System.currentTimeMillis());
  31.          
  32.            Text txCont=new Text("letra-");
  33.             int i;
  34.     @Override
  35.     public void start(Stage stage) {
  36.       i=1;
  37.         final  Scene scene=new Scene(go,400,400,Color.ALICEBLUE);
  38.         stage.setScene(scene);
  39.        
  40.         txletra.setTextOrigin(VPos.TOP);
  41.        
  42.         go.getChildren().add(txletra);
  43.         txletra.setFont(Font.font(STYLESHEET_MODENA, 96));
  44.         txletra.setLayoutX(7);
  45.        
  46.        txletra.layoutXProperty().bind(stage.widthProperty().divide(2));
  47.        txletra.layoutYProperty().bind(stage.heightProperty().divide(2));
  48.         //expressao lmbda
  49.        scene.setOnKeyPressed((KeyEvent event) -> {
  50.            System.out.println(""+event.getText());
  51.            txletra.setText(event.getText());
  52.            
  53.            // System.out.println("entrada random de cor"+c.nextInt(203)+o.nextInt(201)+r.nextInt(201));
  54.            int vlc=c.nextInt(203);
  55.            int vlo=o.nextInt(201);
  56.            int vlr=r.nextInt(201);
  57.            // System.out.println("entrada random de cor"+vlc+","+vlo+","+vlr+",");
  58.            
  59.            scene.setFill(Color.rgb(vlc,vlo,vlr));
  60.            txletra.setFill(Color.rgb(vlr,vlo,vlc));
  61.       txCont.setFill(Color.rgb(vlr,vlo,vlc));
  62.        Text txDigitos=new Text();
  63.      
  64.        i++;
  65.         txCont.setText("letras -"+i);
  66.               txDigitos.setText("-"+event.getText());
  67.                txDigitos.layoutXProperty().bind(stage.widthProperty().subtract(stage.widthProperty()).add(13).multiply(i));
  68.                  txDigitos.layoutYProperty().bind(stage.heightProperty().subtract(80));
  69.         txDigitos.setTextOrigin(VPos.TOP);
  70.         txDigitos.setFont(Font.font(STYLESHEET_MODENA, 25));
  71.         txDigitos.setFill(Color.rgb(vlr,vlc,vlo));
  72.      
  73.        go.getChildren().addAll(txDigitos);
  74.      
  75.        });
  76.        
  77.        
  78.        txCont.setLayoutX(25);
  79.        txCont.layoutYProperty().bind(stage.heightProperty().subtract(96));
  80.        txCont.setTextOrigin(VPos.TOP);
  81.         txCont.setFont(Font.font(STYLESHEET_MODENA, 25));
  82.        
  83.        
  84.        go.getChildren().addAll(txCont);
  85.        
  86.          stage.show();
  87.      }
  88.    
  89.     public static void main(String[] args) {
  90.         launch(args);
  91.     }
  92.    
  93. }
Advertisement
Add Comment
Please, Sign In to add comment