Guest User

eventMauseJFX

a guest
Aug 2nd, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.58 KB | None | 0 0
  1. package fxone;
  2.  
  3. import java.util.Random;
  4. import javafx.application.Application;
  5. import javafx.event.ActionEvent;
  6. import javafx.event.EventHandler;
  7. import javafx.scene.Group;
  8. import javafx.scene.Scene;
  9. import javafx.scene.control.Label;
  10. import javafx.scene.control.Menu;
  11. import javafx.scene.control.MenuBar;
  12. import javafx.scene.control.MenuItem;
  13. import javafx.scene.input.MouseEvent;
  14. import javafx.scene.paint.Color;
  15. import javafx.scene.shape.Line;
  16. import javafx.stage.Stage;
  17. import javafx.stage.StageStyle;
  18.  
  19. /**
  20.  *
  21.  * @author knb's
  22.  *numagrandeviagem.blogspot.com
  23.  * bem10jfx.blogspot.com
  24.  *indentifique mouse e açao no stage,localidade do mouse no stage
  25.  * 2° atualiza?ão do bem10jfx
  26.  * button ativar tracert .
  27.  * buton tracert linear
  28.  * button cores randonicas
  29.  * :)
  30.  */
  31. public class Fxone extends Application {
  32.  String stgOn ,stgOff;
  33.  int stgmi1off,stgmi1on,stgRandon,stgRandoff,stgLineaoff,stgLineon;
  34.  Label lbmouse,lbwith,lbheght;
  35.  MenuBar mb;
  36.  Menu mn;
  37.  MenuItem mi1,mi2,mi3;
  38.   public Line lnesc=new Line();
  39.   public Line lndir=new Line();
  40.   public Line lndown=new Line();
  41.   public Line lnup=new Line();
  42.   public int xx=1;
  43.   public Stage stage;
  44.   double xx1=1;
  45.  
  46.  
  47. public void verd(){
  48.      
  49.  
  50. stgmi1off=1;
  51. stgRandoff=1;
  52. stgLineaoff=1;
  53. }
  54.  @Override
  55.     public void start(Stage xxxx) {
  56.        
  57.         stage=new Stage(StageStyle.DECORATED);
  58.         final Group go=new Group();
  59.         final Scene scene = new Scene(go, 300, 250,Color.BLACK);
  60.         stgOff="Off";stgOn="On";
  61.         stage.setTitle("tracert");
  62.          verd();
  63.      
  64.         lbmouse=new Label("Status: "+stgOff);
  65.         lbwith=new Label("With: XXX");
  66.         lbheght=new Label("Hegth: XXX");
  67.        
  68.         lbmouse.setStyle("-fx-background-color: #2AAA00");
  69.         lbheght.setStyle("-fx-background-color: #5EEE00");
  70.         lbwith.setStyle("-fx-background-color: #7CCC00");
  71.        
  72.         lbmouse.layoutXProperty().bind(
  73.               scene.widthProperty().
  74.                 divide(scene.widthProperty()).
  75.                 add(20)
  76.                 );
  77.        
  78.         lbmouse.layoutYProperty().bind(
  79.              scene.heightProperty().
  80.                 divide(scene.heightProperty()).
  81.                 add(20)
  82.                 );
  83.        
  84.         lbwith.layoutXProperty().bind(
  85.               scene.widthProperty().
  86.                 divide(scene.widthProperty()).add(20)
  87.                 );
  88.        
  89.         lbwith.layoutYProperty().bind(
  90.              scene.heightProperty().
  91.                 divide(scene.heightProperty()).
  92.                 add(35)
  93.                 );
  94.        
  95.         lbheght.layoutXProperty().bind(
  96.               scene.widthProperty().
  97.                 divide(scene.widthProperty()).
  98.                 add(20)
  99.                 );
  100.        
  101.         lbheght.layoutYProperty().bind(
  102.              scene.heightProperty().
  103.                 divide(scene.heightProperty()).
  104.                 add(50)
  105.                 );
  106.        
  107.         go.getChildren().addAll(lbmouse,lbwith,lbheght);
  108. /*HedHot*/
  109.         mb=new MenuBar();
  110.         mn=new Menu("OPÇÕES");
  111.         mi1=new MenuItem("Tracert OFF");
  112.         mi2=new MenuItem("Tracert Linear OFF");
  113.         mi3=new MenuItem("Color Rand OFF ");
  114.        
  115.         mb.getMenus().add(mn);
  116.         mn.getItems().addAll(mi1,mi2,mi3);
  117.         go.getChildren().add(mb);
  118.         mb.layoutXProperty().bind(
  119.                 scene.widthProperty().divide(
  120.                        2).subtract(20));
  121.        /*distak*/
  122.        mi1.setOnAction(new EventHandler<ActionEvent>() {
  123.            @Override
  124.             public void handle(ActionEvent event) {
  125.                 if(1==stgmi1off&&0==stgmi1on){
  126.                  mi1.setText("Tracert ON");
  127.                  stgmi1off=0;
  128.                  stgmi1on=1;
  129.                  go.getChildren().addAll(lndir,lnesc,lnup,lndown);
  130.            
  131.                 }else
  132.                 if(0==stgmi1off&&1==stgmi1on){
  133.                  mi1.setText("Tracert OFF");
  134.                  stgmi1off=1;
  135.                  stgmi1on=0;
  136.                  stgRandoff=1;
  137.                  stgRandon=0;
  138.                   go.getChildren().removeAll(lndir,lnesc,lndown,lnup);
  139.                
  140.                 }
  141.             }
  142.         });
  143.        
  144.        mi2.setOnAction(new EventHandler<ActionEvent>() {
  145.            @Override
  146.             public void handle(ActionEvent event) {
  147.                 if(1==stgRandoff&&0==stgLineon){
  148.                  mi2.setText("Tracert Linear ON");
  149.                  stgLineaoff=0;
  150.                  stgLineon=1;
  151.                
  152.                 }else
  153.                 if(0==stgLineaoff&&1==stgLineon){
  154.                  mi2.setText("Tracert Linear OFF");
  155.                  stgLineaoff=1;
  156.                  stgLineon=0;
  157.                  
  158.                 }
  159.             }
  160.         });
  161.        mi3.setOnAction(new EventHandler<ActionEvent>() {
  162.            @Override
  163.             public void handle(ActionEvent event) {
  164.                 if(1==stgRandoff&&0==stgRandon){
  165.                  mi3.setText("color Rand ON");
  166.                  stgRandoff=0;
  167.                  stgRandon=1;
  168.                  
  169.                  //go.getChildren().addAll(lndir,lnesc,lnup,lndown);
  170.            
  171.                 }else
  172.                 if(0==stgRandoff&&1==stgRandon){
  173.                  mi3.setText("Color Rand OFF");
  174.                  stgRandoff=1;
  175.                  stgRandon=0;
  176.                  
  177.                 }
  178.             }
  179.         });
  180.      
  181.                 lndir.setStrokeWidth(04);
  182.                 lnesc.setStrokeWidth(04);
  183.                 lndown.setStrokeWidth(04);
  184.                 lnup.setStrokeWidth(04);
  185.                    
  186.        scene.setOnMouseMoved(new EventHandler<MouseEvent>() {
  187.            @Override
  188.             public void handle(MouseEvent ev) {
  189.               lbmouse.setText("Status: "+stgOn);
  190.                //tracer engner
  191.                final int wt=(int) ev.getX();
  192.                final int hg=(int) ev.getY();
  193.                
  194.                lbheght.setText("hegth: "+hg);
  195.                lbwith.setText("Width: "+wt);
  196.                 mb.setLayoutY(-25);
  197.                
  198.                 if("Tracert OFF".equals(mi1.getText().toString())){
  199.                 System.out.println("tracert desativado");
  200.                 }else{
  201.                System.out.println("tracert ativado");
  202.                    
  203.        if(stgRandoff==1){
  204.                  System.out.println("rand desativado");
  205.                 lndown.setFill(Color.WHITE);
  206.                 lndown.setStroke(Color.WHITESMOKE);
  207.                 lndir.setFill(Color.WHITE);
  208.                 lndir.setStroke(Color.WHITESMOKE);
  209.                 lnesc.setFill(Color.WHITE);
  210.                 lnesc.setStroke(Color.WHITESMOKE);
  211.                 lnup.setFill(Color.WHITE);
  212.                 lnup.setStroke(Color.WHITESMOKE);
  213.                  
  214.                 }else{
  215.                      Random rand=new Random(System.currentTimeMillis());
  216.                      int p,i,n,t,a,r, e, b,o,m;
  217.                    p=rand.nextInt((int)246);
  218.                    i=rand.nextInt((int)246);
  219.                    n=rand.nextInt((int) 246);
  220.                    t=rand.nextInt((int) 246);
  221.                    a=rand.nextInt((int) 246);
  222.                    r=rand.nextInt((int) 246);
  223.                    e=rand.nextInt((int) 246);
  224.                    b=rand.nextInt((int) 246);
  225.                    o=rand.nextInt((int) 246);
  226.                    m=rand.nextInt((int) 246);
  227.                  System.out.println("color rand ativado"+p+i+n+t+a+r+ e +b+o+m);
  228.                 lndown.setFill(Color.rgb(p, i, m));
  229.                 lndir.setFill(Color.rgb(t, a, r));
  230.                 lnesc.setFill(Color.rgb(e, b, o,.246));
  231.                 lnup.setFill(Color.rgb(o, m, n,.246));
  232.                
  233.                 lndir.setStroke(Color.rgb(p, i, m,.246));
  234.                 lnup.setStroke(Color.rgb(t, a, r,.246));
  235.                 lndown.setStroke(Color.rgb(e, b, o,.246));
  236.                 lnesc.setStroke(Color.rgb(o, m, n,.246));
  237.                
  238.                  }
  239.        if(1==stgLineaoff){
  240.             lndir.setStartX(wt+13);
  241.             lndir.setStartY(hg);
  242.             lndir.endXProperty().bind(
  243.             scene.widthProperty().subtract(10));
  244.                     lndir.setEndY(hg);
  245.             lnesc.setStartX(10);
  246.             lnesc.setStartY(hg);
  247.             lnesc.setEndX(wt-13);
  248.             lnesc.setEndY(hg);
  249.             lnup.setStartX(wt);
  250.             lnup.setStartY(10);
  251.             lnup.setEndX(wt);
  252.             lnup.setEndY(hg-10);
  253.                    
  254.             lndown.setStartX(wt);
  255.             lndown.setStartY(hg+10);
  256.             lndown.setEndX(wt);
  257.             lndown.endYProperty().bind(scene.heightProperty().subtract(10));
  258.                    
  259.                
  260.        }else{
  261.                     if(xx>stage.getHeight()){
  262.                         xx1++;
  263.                         System.out.println("linemode funcionando xx1 em"+xx1);
  264.                         lndir.setStartX(wt+13);
  265.                         lndir.setStartY(hg);
  266.                         lndir.endYProperty().bind(stage.heightProperty());
  267.                         lndir.endXProperty().bind(stage.widthProperty().subtract(xx1));
  268.                      
  269.                         lnesc.setStartX(wt+13);
  270.                         lnesc.setStartY(hg-10);
  271.                         lnesc.setEndY(-stage.getHeight());
  272.                         lnesc.setEndX(xx1);
  273.                      
  274.                      
  275.                     lnup.setStartX(stage.getWidth());
  276.                     lnup.setStartY(xx1);
  277.                     lnup.setEndX(wt-10);
  278.                     lnup.setEndY(hg-10);
  279.                    
  280.                     lndown.setStartX(wt-13);
  281.                     lndown.setStartY(hg);
  282.                     lndown.setEndX(10);
  283.                     System.out.println(
  284.                             "lndown scene.getHeight()-xx1"+(scene.heightProperty().longValue()));
  285.                 lndown.setEndY(scene.heightProperty().longValue()-(xx1));
  286.                        
  287.                        
  288.                     }else{
  289.                        
  290.                         xx++;
  291.                         System.out.println("preparando para gerar linear mode xx"+xx);
  292.                        
  293.                         lndir.setEndY(xx);
  294.                         lndir.setStartX(wt+13);
  295.                         lndir.setStartY(hg);
  296.                         lndir.endXProperty().bind(
  297.                                 scene.widthProperty().subtract(10));
  298.                      
  299.                     lnesc.setStartX(10);
  300.                     lnesc.setStartY(scene.getHeight()-xx);
  301.                     lnesc.setEndX(wt-13);
  302.                     lnesc.setEndY(hg);
  303.                    
  304.                     lnup.setStartX(xx);
  305.                     lnup.setStartY(10);
  306.                     lnup.setEndX(wt);
  307.                     lnup.setEndY(hg-10);
  308.                    
  309.                     lndown.setStartX(wt);
  310.                     lndown.setStartY(hg+10);
  311.                     lndown.setEndX(scene.getWidth()-xx);
  312.                     lndown.endYProperty().bind(scene.heightProperty().subtract(10));
  313.                        
  314.                     }
  315.        }
  316.                 }
  317.              }
  318.         });
  319.          scene.setOnMouseExited(new EventHandler<MouseEvent>() {
  320.             @Override
  321.             public void handle(MouseEvent t) {
  322.             lbmouse.setText("Status: "+stgOff);
  323.              lbheght.setText("hegth: ");
  324.                lbwith.setText("Width: ");
  325.                mb.setLayoutY(1);
  326.             }
  327.         });
  328.         stage.setScene(scene);
  329.         stage.show();
  330.     }
  331.  
  332.  
  333.     public static void main(String[] args) {
  334.         launch(args);
  335.     }
  336. }
Advertisement
Add Comment
Please, Sign In to add comment