Guest User

MOVEDEVENT_JFX

a guest
Jun 20th, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.31 KB | None | 0 0
  1. package retangulos;
  2. import javafx.application.Application;
  3. import javafx.event.EventHandler;
  4. import javafx.scene.Group;
  5. import javafx.scene.Scene;
  6. import javafx.scene.input.KeyCode;
  7. import javafx.scene.input.KeyEvent;
  8. import javafx.scene.layout.VBox;
  9. import javafx.scene.paint.Color;
  10. import javafx.scene.shape.Rectangle;
  11. import javafx.scene.text.Text;
  12. import javafx.stage.Stage;
  13.  
  14. /*
  15.  @author k_libre
  16.  */
  17. public class Retangulos extends Application {
  18.      public Text txinf,txposiW1I,txposiW1F,txposiW2I,txposiW2F,txpres;
  19.      public int strTxposiW1I =0;
  20.      public int strTxposiW1F = 0;
  21.      public int strTxposiW2I = 0;
  22.      public int strTxposiW2F = 0;
  23.      public String strTxpres ="_";
  24.      public Rectangle rec1=new Rectangle();
  25.      public int ix=+15;
  26.      public int iy=+15;
  27.        
  28.     @Override
  29.     public void start(Stage stage) {
  30.     /////////////////////////////////////////////////////////////////////////////
  31.         stage.setTitle("rectanglers");
  32.         Group go=new Group();
  33.         Scene scene=new Scene(go,400,400,Color.ALICEBLUE);
  34.         stage.setScene(scene);
  35.         ////////////////////////////////////////////////////////////////////
  36.        
  37.         txinf=new Text("informaçoes");
  38.         txposiW1I=new Text("posiçao Inicial rec1I: "+strTxposiW1I);
  39.         txposiW1F=new Text("posiçao Final   rec1F: "+strTxposiW1F);
  40.         txposiW2I=new Text("posiçao Inicial rec2I: "+strTxposiW2I);
  41.         txposiW2F=new Text("posiçao Final   rec2F: "+strTxposiW2F);
  42.         txpres=new Text("press");
  43.         VBox vbPosis=new VBox(0.5);
  44.         go.getChildren().add(vbPosis);
  45.        
  46.         vbPosis.getChildren().addAll(
  47.              txinf,txposiW1I,txposiW1F,
  48.              txposiW2I,txposiW2F,txpres
  49.      );
  50.        
  51.         rec1.setHeight(40);
  52.         rec1.setWidth(40);
  53.         rec1.setFill(Color.RED);
  54.         rec1.setArcHeight(10);
  55.         rec1.setArcWidth(10);
  56.         go.getChildren().add(rec1);
  57.      
  58. scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
  59.     @Override
  60.     public void handle(KeyEvent keys) {
  61.         if(keys.getCode()==KeyCode.W){
  62.              System.out.println("Press Cima w=" + keys.getText());
  63.              rec1.setLayoutY(--iy);
  64.          }
  65.         if(keys.getCode()==KeyCode.S){
  66.              System.out.println("Press Baixo s=" + keys.getText()+"moved to "+iy);
  67.              rec1.setLayoutY(++iy);
  68.         }
  69.         if(keys.getCode()==KeyCode.A){
  70.              System.out.println("Press esc a= " + keys.getText());
  71.                rec1.setLayoutX(--ix);
  72.          }
  73.         if(keys.getCode()==KeyCode.D){
  74.              System.out.println("Press dir d=" + keys.getText());
  75.                 rec1.setLayoutX(++ix);
  76.          }
  77.        
  78.         strTxpres=keys.getText();
  79.         strTxposiW1I=ix;
  80.         strTxposiW1F=(int) (ix+ rec1.getWidth());
  81.         strTxposiW2I=iy;
  82.         strTxposiW2F=(int) (iy+rec1.getHeight());
  83.         txpres.setText("press:.:"+ strTxpres);
  84.         txposiW1I.setText("posiçao Inicial rec1I: "+strTxposiW1I);
  85.         txposiW1F.setText("posiçao Final   rec1F: "+strTxposiW1F);
  86.         txposiW2I.setText("posiçao Inicial rec2I: "+strTxposiW2I);
  87.         txposiW2F.setText("posiçao Final   rec2F: "+strTxposiW2F);
  88.      }
  89. });
  90.          stage.show();
  91.     }
  92.     public static void main(String[] args) {
  93.       Retangulos.launch(args);
  94.     }
Advertisement
Add Comment
Please, Sign In to add comment