Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package fxone;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.scene.Group;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.input.MouseEvent;
- import javafx.scene.layout.StackPane;
- import javafx.scene.paint.Color;
- import javafx.scene.shape.Line;
- import javafx.stage.Stage;
- import javafx.stage.StageStyle;
- /**
- *
- * @author knb's
- *numagrandeviagem.blogspot.com
- *indentifique mouse e aรงao no stage,localidade do mouse no stage
- */
- public class FxOne extends Application {
- private String stgOn ,stgOff;
- @Override
- public void start(Stage stage) {
- stage=new Stage(StageStyle.DECORATED);
- Group go=new Group();
- final Scene scene = new Scene(go, 600, 450,Color.BLACK);
- stgOff="Off";stgOn="On";
- stage.setTitle("Hello World!");
- final Label lbmouse,lbwith,lbheght;
- lbmouse=new Label("Status: "+stgOff);
- lbwith=new Label("With: XXX");
- lbheght=new Label("Hegth: XXX");
- lbmouse.setStyle("-fx-background-color: #7FFF00");
- lbheght.setStyle("-fx-background-color: #7FFF00");
- lbwith.setStyle("-fx-background-color: #7FFF00");
- lbmouse.layoutXProperty().bind(
- scene.widthProperty().
- divide(scene.widthProperty()).
- add(20)
- );;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- lbmouse.layoutYProperty().bind(
- scene.heightProperty().
- divide(scene.heightProperty()).
- add(20)
- );;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- lbwith.layoutXProperty().bind(
- scene.widthProperty().
- divide(scene.widthProperty()).add(20)
- );;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- lbwith.layoutYProperty().bind(
- scene.heightProperty().
- divide(scene.heightProperty()).
- add(35)
- );;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- lbheght.layoutXProperty().bind(
- scene.widthProperty().
- divide(scene.widthProperty()).
- add(20)
- );;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- lbheght.layoutYProperty().bind(
- scene.heightProperty().
- divide(scene.heightProperty()).
- add(50)
- );;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- go.getChildren().addAll(lbmouse,lbwith,lbheght);
- scene.setOnMouseMoved(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent t) {
- lbmouse.setText("Status: "+stgOn);
- //tracer engner
- final int wt=(int) t.getX();
- final int hg=(int) t.getY();
- lbheght.setText("hegth: "+hg);
- lbwith.setText("Width: "+wt);
- }
- });
- scene.setOnMouseExited(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent t) {
- lbmouse.setText("Status: "+stgOff);
- lbheght.setText("hegth: ");
- lbwith.setText("Width: ");
- }
- });
- stage.setScene(scene);
- stage.show();
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment