Guest User

LocalizeStatusIndPositions_JAVAFX

a guest
Oct 12th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.53 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package fxone;
  6.  
  7. import javafx.application.Application;
  8. import javafx.event.ActionEvent;
  9. import javafx.event.EventHandler;
  10. import javafx.scene.Group;
  11. import javafx.scene.Scene;
  12. import javafx.scene.control.Button;
  13. import javafx.scene.control.Label;
  14. import javafx.scene.input.MouseEvent;
  15. import javafx.scene.layout.StackPane;
  16. import javafx.scene.paint.Color;
  17. import javafx.scene.shape.Line;
  18. import javafx.stage.Stage;
  19. import javafx.stage.StageStyle;
  20.  
  21. /**
  22.  *
  23.  * @author knb's
  24.  *numagrandeviagem.blogspot.com
  25.  *indentifique mouse e aรงao no stage,localidade do mouse no stage
  26.  */
  27. public class FxOne extends Application {
  28. private String stgOn ,stgOff;
  29.     @Override
  30.     public void start(Stage stage) {
  31.         stage=new Stage(StageStyle.DECORATED);
  32.         Group go=new Group();
  33.         final Scene scene = new Scene(go, 600, 450,Color.BLACK);
  34.        stgOff="Off";stgOn="On";
  35.         stage.setTitle("Hello World!");
  36.         final Label lbmouse,lbwith,lbheght;
  37.         lbmouse=new Label("Status: "+stgOff);
  38.         lbwith=new Label("With: XXX");
  39.         lbheght=new Label("Hegth: XXX");
  40.         lbmouse.setStyle("-fx-background-color: #7FFF00");
  41.         lbheght.setStyle("-fx-background-color: #7FFF00");
  42.         lbwith.setStyle("-fx-background-color: #7FFF00");
  43.        
  44.         lbmouse.layoutXProperty().bind(
  45.               scene.widthProperty().
  46.                 divide(scene.widthProperty()).
  47.                 add(20)
  48.                 );;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  49.        
  50.         lbmouse.layoutYProperty().bind(
  51.              scene.heightProperty().
  52.                 divide(scene.heightProperty()).
  53.                 add(20)
  54.                 );;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  55.        
  56.         lbwith.layoutXProperty().bind(
  57.               scene.widthProperty().
  58.                 divide(scene.widthProperty()).add(20)
  59.                 );;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  60.        
  61.         lbwith.layoutYProperty().bind(
  62.              scene.heightProperty().
  63.                 divide(scene.heightProperty()).
  64.                 add(35)
  65.                 );;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  66.        
  67.         lbheght.layoutXProperty().bind(
  68.               scene.widthProperty().
  69.                 divide(scene.widthProperty()).
  70.                 add(20)
  71.                 );;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  72.        
  73.         lbheght.layoutYProperty().bind(
  74.              scene.heightProperty().
  75.                 divide(scene.heightProperty()).
  76.                 add(50)
  77.                 );;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  78.          
  79.         go.getChildren().addAll(lbmouse,lbwith,lbheght);
  80.        
  81.         scene.setOnMouseMoved(new EventHandler<MouseEvent>() {
  82.            @Override
  83.             public void handle(MouseEvent t) {
  84.               lbmouse.setText("Status: "+stgOn);
  85.                //tracer engner
  86.                final int wt=(int) t.getX();
  87.                final int hg=(int) t.getY();
  88.                
  89.                lbheght.setText("hegth: "+hg);
  90.                lbwith.setText("Width: "+wt);
  91.              }
  92.         });
  93.          scene.setOnMouseExited(new EventHandler<MouseEvent>() {
  94.             @Override
  95.             public void handle(MouseEvent t) {
  96.             lbmouse.setText("Status: "+stgOff);
  97.              lbheght.setText("hegth: ");
  98.                lbwith.setText("Width: ");
  99.             }
  100.         });
  101.         stage.setScene(scene);
  102.         stage.show();
  103.     }
  104.  
  105.  
  106.     public static void main(String[] args) {
  107.         launch(args);
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment