WIP : Brad_GraphPiece #25
| @ -1,32 +1,222 @@ | |||||||
| /* |  | ||||||
|  * This Java source file was generated by the Gradle 'init' task. |  | ||||||
|  */ |  | ||||||
| package school_project;   | package school_project;   | ||||||
|  |  | ||||||
| import javafx.application.Application; | import javafx.application.Application; | ||||||
|  | import javafx.scene.Node; | ||||||
|  | import javafx.event.EventHandler; | ||||||
| import javafx.scene.Group; | import javafx.scene.Group; | ||||||
| import javafx.scene.Scene; | import javafx.scene.Scene; | ||||||
| import javafx.scene.control.Button; | import javafx.scene.Cursor; | ||||||
|  | import javafx.scene.input.KeyEvent; | ||||||
|  | import javafx.scene.input.MouseEvent; | ||||||
|  | import javafx.scene.paint.Color;   | ||||||
|  | import javafx.scene.shape.Polygon; | ||||||
|  | import javafx.scene.transform.Rotate; | ||||||
|  | import javafx.animation.RotateTransition; | ||||||
| import javafx.stage.Stage; | import javafx.stage.Stage; | ||||||
|  | import javafx.util.Duration; | ||||||
|  | public class Controller extends Application{ | ||||||
|  | 	 | ||||||
|  | 	double x; | ||||||
|  | 	double y; | ||||||
| 	 | 	 | ||||||
|  | |||||||
| public class Controller extends Application { |  | ||||||
| 	  | 	  | ||||||
|     @Override |  | ||||||
| 	public void start(Stage primaryStage) throws Exception { | 	public void start(Stage primaryStage) throws Exception { | ||||||
|         primaryStage.setTitle("test"); | 		 | ||||||
|         Button btn = new Button("test"); | 		Polygon piece1 = new Polygon(); | ||||||
|         btn.setOnAction(event -> System.out.println("hey")); | 		Polygon piece2 = new Polygon(); | ||||||
|  | 		Polygon piece3 = new Polygon(); | ||||||
|  | 		Polygon piece4 = new Polygon(); | ||||||
|  | 		Polygon piece5 = new Polygon(); | ||||||
|  | 		Polygon piece6 = new Polygon(); | ||||||
|  | 		Polygon piece7 = new Polygon(); | ||||||
|  |  | ||||||
|  | 		 | ||||||
|  | 		 | ||||||
|  | 		 piece1.getPoints().addAll(new Double [] { | ||||||
|  | 				 0.0,0.0, | ||||||
|  | 				 200.0,0.0, | ||||||
|  | 				 200.0,200.0, | ||||||
|  | 				 100.0,200.0, | ||||||
|  | 				 100.0,100.0, | ||||||
|  | 				 0.0,100.0}); | ||||||
|  | 		  | ||||||
|  | 		 piece2.getPoints().addAll(new Double [] { | ||||||
|  | 				 100.0,0.0, | ||||||
|  | 				 200.0,0.0, | ||||||
|  | 				 200.0,300.0, | ||||||
|  | 				 100.0,300.0, | ||||||
|  | 				 }); | ||||||
|  | 		  | ||||||
|  | 		 piece3.getPoints().addAll(new Double [] { | ||||||
|  | 				 0.0,0.0, | ||||||
|  | 				 200.0,0.0, | ||||||
|  | 				 200.0,200.0, | ||||||
|  | 				 0.0,200.0, | ||||||
|  | 				 }); | ||||||
|  | 		  | ||||||
|  | 		 piece4.getPoints().addAll(new Double [] { | ||||||
|  | 				 0.0,0.0, | ||||||
|  | 				 200.0,0.0, | ||||||
|  | 				 200.0,300.0, | ||||||
|  | 				 0.0,300.0, | ||||||
|  | 				  | ||||||
|  | 		 }); | ||||||
|  | 		  | ||||||
|  | 		 piece5.getPoints().addAll(new Double [] { | ||||||
|  | 				 0.0,0.0, | ||||||
|  | 				 100.0,0.0, | ||||||
|  | 				 100.0,100.0, | ||||||
|  | 				 0.0,100.0, | ||||||
|  | 				 }); | ||||||
|  | 		  | ||||||
|  | 		 piece6.getPoints().addAll(new Double [] { | ||||||
|  | 				 0.0,0.0, | ||||||
|  | 				 200.0,0.0, | ||||||
|  | 				 200.0,300.0, | ||||||
|  | 				 100.0,300.0, | ||||||
|  | 				 100.0,100.0, | ||||||
|  | 				 0.0,100.0}); | ||||||
|  | 		  | ||||||
|  | 		 piece7.getPoints().addAll(new Double [] { | ||||||
|  | 				 100.0,0.0, | ||||||
|  | 				 200.0,0.0, | ||||||
|  | 				 200.0,200.0, | ||||||
|  | 				 100.0,200.0, | ||||||
|  | 				 }); | ||||||
|  | 		 | ||||||
|  | 		 /*for(int i ; i<tab.lenght ; i++ ) { | ||||||
|  | 			for (int j , i<tab.widnth , j++) { | ||||||
|  | 				 | ||||||
|  | 				if (tab[0][0]==TRUE;) { | ||||||
|  | 					if(tab[ | ||||||
|  | 				 | ||||||
|  | 					 | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		}*/ | ||||||
|  | 		 | ||||||
|  | 		 | ||||||
| 	 | 	 | ||||||
| 		 Group root = new Group();   | 		 Group root = new Group();   | ||||||
|         root.getChildren().add(btn); | 	        root.getChildren().addAll(piece2,piece1,piece3,piece4,piece5,piece6,piece7/*,....,pieceN*/);   | ||||||
|  | 	        Scene scene = new Scene(root,690,650,Color.WHEAT);   | ||||||
|         Scene scene = new Scene(root, 300,300); | 	        root.getChildren().forEach(n -> makeDraggable((Polygon) n)); | ||||||
|  | 	        root.getChildren().forEach(n -> rotation((Polygon) n, scene)); | ||||||
| 	        primaryStage.setScene(scene);   | 	        primaryStage.setScene(scene);   | ||||||
|  | 	        primaryStage.setTitle("piece 1");  | ||||||
| 	         | 	         | ||||||
| 	        primaryStage.show();  | 	        primaryStage.show();  | ||||||
|  | 		 | ||||||
|  | 		 | ||||||
|  | 		  | ||||||
|  | 		 piece1.setFill(Color.LIMEGREEN); | ||||||
|  | 		 piece1.setStroke(Color.BLACK); | ||||||
|  | 		 piece1.setStrokeWidth(3); | ||||||
|  | 		  | ||||||
|  | 		 piece2.setFill(Color.LIMEGREEN); | ||||||
|  | 		 piece2.setStroke(Color.BLACK); | ||||||
|  | 		 piece2.setStrokeWidth(3); | ||||||
|  | 		  | ||||||
|  | 		 piece3.setFill(Color.LIMEGREEN); | ||||||
|  | 		 piece3.setStroke(Color.BLACK); | ||||||
|  | 		 piece3.setStrokeWidth(3); | ||||||
|  | 		  | ||||||
|  | 		 piece4.setFill(Color.LIMEGREEN); | ||||||
|  | 		 piece4.setStroke(Color.BLACK); | ||||||
|  | 		 piece4.setStrokeWidth(3); | ||||||
|  | 		  | ||||||
|  | 		 piece5.setFill(Color.LIMEGREEN); | ||||||
|  | 		 piece5.setStroke(Color.BLACK); | ||||||
|  | 		 piece5.setStrokeWidth(3); | ||||||
|  | 		  | ||||||
|  | 		 piece6.setFill(Color.LIMEGREEN); | ||||||
|  | 		 piece6.setStroke(Color.BLACK); | ||||||
|  | 		 piece6.setStrokeWidth(3); | ||||||
|  | 		  | ||||||
|  | 		 piece7.setFill(Color.LIMEGREEN); | ||||||
|  | 		 piece7.setStroke(Color.BLACK); | ||||||
|  | 		 piece7.setStrokeWidth(3); | ||||||
|  | 		 		  | ||||||
|  | 		 | ||||||
|  | 	} | ||||||
|  | 	//double click delayed bug to fix | ||||||
|  | 	//ftm just the last piece implemented can be rotated  | ||||||
|  | 	public static void rotaterght (Node node) { | ||||||
|  | 		 RotateTransition rotaterght = new RotateTransition(); | ||||||
|  | 			//setting attributes for the RotateTransition   | ||||||
|  | 			 rotaterght.setByAngle(90); | ||||||
|  | 			 rotaterght.autoReverseProperty(); | ||||||
|  | 			 rotaterght.setDuration(Duration.millis(1000)); | ||||||
|  | 			 rotaterght.setNode(node); | ||||||
|  | 			 rotaterght.setAxis(Rotate.Z_AXIS); | ||||||
|  | 			 rotaterght.play();} | ||||||
|  | 	  | ||||||
|  | 	 public static void rotatelft (Node node) {	  | ||||||
|  | 			 | ||||||
|  | 			 RotateTransition rotatelft = new RotateTransition(); | ||||||
|  | 			  | ||||||
|  | 			 rotatelft.setByAngle(-90);// minus to rotate to the left | ||||||
|  | 			 rotatelft.autoReverseProperty(); | ||||||
|  | 			 rotatelft.setDuration(Duration.millis(1000)); | ||||||
|  | 			 rotatelft.setNode(node); | ||||||
|  | 			 rotatelft.setAxis(Rotate.Z_AXIS); | ||||||
|  | 			 rotatelft.play();} | ||||||
|  | 	  | ||||||
|  | 	 public void rotation (Polygon node, Scene scene) { | ||||||
|  | 		  scene.setOnKeyPressed(new EventHandler<KeyEvent>() { | ||||||
|  | 			 public void handle(KeyEvent event) {// 'event' means corresponds to clicking on the clipboard | ||||||
|  | 				 switch (event.getCode()) {// 'getCode' gets the code of the key pressed on the clipboard | ||||||
|  | 				 case RIGHT: rotaterght(node);   break; | ||||||
|  | 				 //args to set  | ||||||
|  | 				 case LEFT: rotatelft(node);  break; | ||||||
|  | 				 default: System.out.println("this case hasn't been taken in charge yet"); | ||||||
|  | 				  | ||||||
|  | 				 } | ||||||
|  | 			 } | ||||||
|  | 	  }); | ||||||
| 	  } | 	  } | ||||||
| 			   | 			   | ||||||
|  | 	  | ||||||
|  |  | ||||||
|  | 	  public void makeDraggable(Polygon node) { | ||||||
|  | 		 	node.setOnMousePressed(new EventHandler<MouseEvent>() { | ||||||
|  | 			  @Override public void handle(MouseEvent mouseEvent) { | ||||||
|  | 			    // record a (x,y) distance for the drag and drop operation. | ||||||
|  | 			    x = node.getLayoutX() - mouseEvent.getSceneX(); | ||||||
|  | 			    y = node.getLayoutY() - mouseEvent.getSceneY(); | ||||||
|  | 			    node.requestFocus(); | ||||||
|  | 			    node.setFocusTraversable(true); | ||||||
|  | 			    node.focusedProperty(); | ||||||
|  | 			    node.focusVisibleProperty(); | ||||||
|  | 			    /*node.setFocused(true);*/ | ||||||
|  | 			    node.setCursor(Cursor.CLOSED_HAND); | ||||||
|  | 			    node.setFill(Color.AZURE); | ||||||
|  | 			  } | ||||||
|  | 			}); | ||||||
|  | 		  | ||||||
|  | 			node.setOnMouseReleased(new EventHandler<MouseEvent>() { | ||||||
|  | 			  @Override public void handle(MouseEvent mouseEvent) { | ||||||
|  | 			    node.setCursor(Cursor.HAND); | ||||||
|  | 			    node.setFill(Color.LIMEGREEN); | ||||||
|  | 			  } | ||||||
|  | 			}); | ||||||
|  | 			 | ||||||
|  | 			node.setOnMouseDragged(new EventHandler<MouseEvent>() { | ||||||
|  | 			  @Override public void handle(MouseEvent mouseEvent) { | ||||||
|  | 			    node.setLayoutX(mouseEvent.getSceneX() + x); | ||||||
|  | 			    node.setLayoutY(mouseEvent.getSceneY() + y); | ||||||
|  | 			  } | ||||||
|  | 			}); | ||||||
|  | 			 | ||||||
|  | 			node.setOnMouseEntered(new EventHandler<MouseEvent>() { | ||||||
|  | 			  @Override public void handle(MouseEvent mouseEvent) { | ||||||
|  | 			    node.setCursor(Cursor.HAND); | ||||||
|  | 			  } | ||||||
|  | 			}); | ||||||
|  | 			 | ||||||
|  | 		 } | ||||||
|  |  | ||||||
|  | 	 | ||||||
| 	public static void main(String[] args) {   | 	public static void main(String[] args) {   | ||||||
|        launch(); |         launch(args);   | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	
Il faut que le nom de ta classe soit le nom du fichier.
Donc il faut
public class Controller extends Application{