Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fxone;
- import java.util.Random;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.scene.Group;
- import javafx.scene.Scene;
- import javafx.scene.control.Label;
- import javafx.scene.control.Menu;
- import javafx.scene.control.MenuBar;
- import javafx.scene.control.MenuItem;
- import javafx.scene.input.MouseEvent;
- import javafx.scene.paint.Color;
- import javafx.scene.shape.Line;
- import javafx.stage.Stage;
- import javafx.stage.StageStyle;
- /**
- *
- * @author knb's
- *numagrandeviagem.blogspot.com
- * bem10jfx.blogspot.com
- *indentifique mouse e açao no stage,localidade do mouse no stage
- * 2° atualiza?ão do bem10jfx
- * button ativar tracert .
- * buton tracert linear
- * button cores randonicas
- * :)
- */
- public class Fxone extends Application {
- String stgOn ,stgOff;
- int stgmi1off,stgmi1on,stgRandon,stgRandoff,stgLineaoff,stgLineon;
- Label lbmouse,lbwith,lbheght;
- MenuBar mb;
- Menu mn;
- MenuItem mi1,mi2,mi3;
- public Line lnesc=new Line();
- public Line lndir=new Line();
- public Line lndown=new Line();
- public Line lnup=new Line();
- public int xx=1;
- public Stage stage;
- double xx1=1;
- public void verd(){
- stgmi1off=1;
- stgRandoff=1;
- stgLineaoff=1;
- }
- @Override
- public void start(Stage xxxx) {
- stage=new Stage(StageStyle.DECORATED);
- final Group go=new Group();
- final Scene scene = new Scene(go, 300, 250,Color.BLACK);
- stgOff="Off";stgOn="On";
- stage.setTitle("tracert");
- verd();
- lbmouse=new Label("Status: "+stgOff);
- lbwith=new Label("With: XXX");
- lbheght=new Label("Hegth: XXX");
- lbmouse.setStyle("-fx-background-color: #2AAA00");
- lbheght.setStyle("-fx-background-color: #5EEE00");
- lbwith.setStyle("-fx-background-color: #7CCC00");
- 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);
- /*HedHot*/
- mb=new MenuBar();
- mn=new Menu("OPÇÕES");
- mi1=new MenuItem("Tracert OFF");
- mi2=new MenuItem("Tracert Linear OFF");
- mi3=new MenuItem("Color Rand OFF ");
- mb.getMenus().add(mn);
- mn.getItems().addAll(mi1,mi2,mi3);
- go.getChildren().add(mb);
- mb.layoutXProperty().bind(
- scene.widthProperty().divide(
- 2).subtract(20));
- /*distak*/
- mi1.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- if(1==stgmi1off&&0==stgmi1on){
- mi1.setText("Tracert ON");
- stgmi1off=0;
- stgmi1on=1;
- go.getChildren().addAll(lndir,lnesc,lnup,lndown);
- }else
- if(0==stgmi1off&&1==stgmi1on){
- mi1.setText("Tracert OFF");
- stgmi1off=1;
- stgmi1on=0;
- stgRandoff=1;
- stgRandon=0;
- go.getChildren().removeAll(lndir,lnesc,lndown,lnup);
- }
- }
- });
- mi2.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- if(1==stgRandoff&&0==stgLineon){
- mi2.setText("Tracert Linear ON");
- stgLineaoff=0;
- stgLineon=1;
- }else
- if(0==stgLineaoff&&1==stgLineon){
- mi2.setText("Tracert Linear OFF");
- stgLineaoff=1;
- stgLineon=0;
- }
- }
- });
- mi3.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- if(1==stgRandoff&&0==stgRandon){
- mi3.setText("color Rand ON");
- stgRandoff=0;
- stgRandon=1;
- //go.getChildren().addAll(lndir,lnesc,lnup,lndown);
- }else
- if(0==stgRandoff&&1==stgRandon){
- mi3.setText("Color Rand OFF");
- stgRandoff=1;
- stgRandon=0;
- }
- }
- });
- lndir.setStrokeWidth(04);
- lnesc.setStrokeWidth(04);
- lndown.setStrokeWidth(04);
- lnup.setStrokeWidth(04);
- scene.setOnMouseMoved(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent ev) {
- lbmouse.setText("Status: "+stgOn);
- //tracer engner
- final int wt=(int) ev.getX();
- final int hg=(int) ev.getY();
- lbheght.setText("hegth: "+hg);
- lbwith.setText("Width: "+wt);
- mb.setLayoutY(-25);
- if("Tracert OFF".equals(mi1.getText().toString())){
- System.out.println("tracert desativado");
- }else{
- System.out.println("tracert ativado");
- if(stgRandoff==1){
- System.out.println("rand desativado");
- lndown.setFill(Color.WHITE);
- lndown.setStroke(Color.WHITESMOKE);
- lndir.setFill(Color.WHITE);
- lndir.setStroke(Color.WHITESMOKE);
- lnesc.setFill(Color.WHITE);
- lnesc.setStroke(Color.WHITESMOKE);
- lnup.setFill(Color.WHITE);
- lnup.setStroke(Color.WHITESMOKE);
- }else{
- Random rand=new Random(System.currentTimeMillis());
- int p,i,n,t,a,r, e, b,o,m;
- p=rand.nextInt((int)246);
- i=rand.nextInt((int)246);
- n=rand.nextInt((int) 246);
- t=rand.nextInt((int) 246);
- a=rand.nextInt((int) 246);
- r=rand.nextInt((int) 246);
- e=rand.nextInt((int) 246);
- b=rand.nextInt((int) 246);
- o=rand.nextInt((int) 246);
- m=rand.nextInt((int) 246);
- System.out.println("color rand ativado"+p+i+n+t+a+r+ e +b+o+m);
- lndown.setFill(Color.rgb(p, i, m));
- lndir.setFill(Color.rgb(t, a, r));
- lnesc.setFill(Color.rgb(e, b, o,.246));
- lnup.setFill(Color.rgb(o, m, n,.246));
- lndir.setStroke(Color.rgb(p, i, m,.246));
- lnup.setStroke(Color.rgb(t, a, r,.246));
- lndown.setStroke(Color.rgb(e, b, o,.246));
- lnesc.setStroke(Color.rgb(o, m, n,.246));
- }
- if(1==stgLineaoff){
- lndir.setStartX(wt+13);
- lndir.setStartY(hg);
- lndir.endXProperty().bind(
- scene.widthProperty().subtract(10));
- lndir.setEndY(hg);
- lnesc.setStartX(10);
- lnesc.setStartY(hg);
- lnesc.setEndX(wt-13);
- lnesc.setEndY(hg);
- lnup.setStartX(wt);
- lnup.setStartY(10);
- lnup.setEndX(wt);
- lnup.setEndY(hg-10);
- lndown.setStartX(wt);
- lndown.setStartY(hg+10);
- lndown.setEndX(wt);
- lndown.endYProperty().bind(scene.heightProperty().subtract(10));
- }else{
- if(xx>stage.getHeight()){
- xx1++;
- System.out.println("linemode funcionando xx1 em"+xx1);
- lndir.setStartX(wt+13);
- lndir.setStartY(hg);
- lndir.endYProperty().bind(stage.heightProperty());
- lndir.endXProperty().bind(stage.widthProperty().subtract(xx1));
- lnesc.setStartX(wt+13);
- lnesc.setStartY(hg-10);
- lnesc.setEndY(-stage.getHeight());
- lnesc.setEndX(xx1);
- lnup.setStartX(stage.getWidth());
- lnup.setStartY(xx1);
- lnup.setEndX(wt-10);
- lnup.setEndY(hg-10);
- lndown.setStartX(wt-13);
- lndown.setStartY(hg);
- lndown.setEndX(10);
- System.out.println(
- "lndown scene.getHeight()-xx1"+(scene.heightProperty().longValue()));
- lndown.setEndY(scene.heightProperty().longValue()-(xx1));
- }else{
- xx++;
- System.out.println("preparando para gerar linear mode xx"+xx);
- lndir.setEndY(xx);
- lndir.setStartX(wt+13);
- lndir.setStartY(hg);
- lndir.endXProperty().bind(
- scene.widthProperty().subtract(10));
- lnesc.setStartX(10);
- lnesc.setStartY(scene.getHeight()-xx);
- lnesc.setEndX(wt-13);
- lnesc.setEndY(hg);
- lnup.setStartX(xx);
- lnup.setStartY(10);
- lnup.setEndX(wt);
- lnup.setEndY(hg-10);
- lndown.setStartX(wt);
- lndown.setStartY(hg+10);
- lndown.setEndX(scene.getWidth()-xx);
- lndown.endYProperty().bind(scene.heightProperty().subtract(10));
- }
- }
- }
- }
- });
- scene.setOnMouseExited(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent t) {
- lbmouse.setText("Status: "+stgOff);
- lbheght.setText("hegth: ");
- lbwith.setText("Width: ");
- mb.setLayoutY(1);
- }
- });
- stage.setScene(scene);
- stage.show();
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment