Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.65 KB | None | 0 0
  1.  
  2. import javafx.application.Application;
  3. import javafx.scene.Scene;
  4. import javafx.scene.layout.Background;
  5. import javafx.scene.paint.Color;
  6. import javafx.scene.control.Button;
  7. import javafx.scene.control.Label;
  8. import javafx.scene.control.TextField;
  9. import javafx.scene.layout.Pane;
  10. import javafx.stage.Stage;
  11. import javafx.event.ActionEvent;
  12. import javafx.event.EventHandler;
  13. import javax.swing.JOptionPane;
  14. import javax.swing.JComboBox;
  15. import javafx.scene.shape.*;
  16. import javafx.scene.text.*; import javafx.scene.shape.Circle;
  17. import javafx.util.Duration;
  18. import javafx.animation.TranslateTransition;
  19. import javafx.animation.ScaleTransition;
  20. import javafx.scene.image.Image;
  21. import javafx.scene.image.ImageView;
  22. import java.io.FileInputStream;
  23. import java.io.FileNotFoundException;
  24. import javafx.scene.input.MouseEvent;
  25. import javafx.scene.Cursor;
  26. import javafx.scene.effect.DropShadow;
  27. import javafx.concurrent.Service;
  28. import javafx.concurrent.Task;
  29. import java.io.InputStream;
  30. import javafx.scene.layout.BackgroundImage;
  31. import javafx.scene.layout.Background;
  32. import javafx.scene.layout.BackgroundSize;
  33. import javafx.scene.layout.BackgroundPosition;
  34. import javafx.scene.layout.BackgroundRepeat;
  35. import javafx.animation.FadeTransition;
  36. import javafx.animation.SequentialTransition;
  37. import javafx.animation.ParallelTransition;
  38. import java.util.ArrayList;
  39. import javafx.geometry.Bounds;
  40.  
  41.  
  42. public class sample extends Application{
  43. Pane pane = new Pane(); int studCount = 0; int guide = 0, ageValue=0;
  44. Button add, vaccinate, next, none;
  45. TextField ageField; Text ageWarning, noStudents;
  46. Text treeText[] = new Text[8]; Circle round[] = new Circle[8]; ImageView tails[] = new ImageView[8];
  47. Button student[]; ArrayList<Integer> numGuide = new ArrayList<Integer>(); int copy[] = new int[studCount];
  48. Button studenta, studentb, studentc, studentd, studente, studentf, studentg;
  49. TranslateTransition toWalk1 = new TranslateTransition(Duration.seconds(4));TranslateTransition toWalk2 = new TranslateTransition(Duration.seconds(4));TranslateTransition toWalk3 = new TranslateTransition(Duration.seconds(4));TranslateTransition toWalk4 = new TranslateTransition(Duration.seconds(3));TranslateTransition toWalk5 = new TranslateTransition(Duration.seconds(3));TranslateTransition toWalk6 = new TranslateTransition(Duration.seconds(2));TranslateTransition toWalk7 = new TranslateTransition(Duration.seconds(2));
  50. TranslateTransition roomOut = new TranslateTransition(Duration.seconds(6));TranslateTransition roomIn = new TranslateTransition(Duration.seconds(3));
  51. ScaleTransition treePop = new ScaleTransition(Duration.seconds(.5)); ScaleTransition roundPop = new ScaleTransition(Duration.seconds(.5));
  52. ParallelTransition pt = new ParallelTransition(treePop, roundPop);
  53. // Service studentExit = new exit();Service flip = new flipBack(); Service afterExit = new sixSec(); Service treeWait = new threeSec();
  54.  
  55.  
  56.  
  57.  
  58. TranslateTransition nextMove = new TranslateTransition(Duration.seconds(1));
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. @Override
  70. public void start(Stage primaryStage) throws FileNotFoundException {
  71. student = new Button[8];
  72.  
  73. add = new Button("ADD");
  74. vaccinate = new Button("VACCINATE");
  75. ageField = new TextField();
  76. ageWarning = new Text("Please Enter Age!");
  77. noStudents = new Text("There's no student!");
  78. next = new Button("NEXT");
  79. none = new Button("NONE");
  80. addNew();
  81.  
  82.  
  83.  
  84. studenta = new Button("");
  85. studentb = new Button("");
  86. studentc = new Button("");
  87. studentd = new Button("");
  88. studente = new Button("");
  89. studentf = new Button("");
  90. studentg = new Button("");
  91. students();
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98. numGuide.add(9);
  99. student[1] = studenta;
  100. student[2] = studentb;
  101. student[3] = studentc;
  102. student[4] = studentd;
  103. student[5] = studente;
  104. student[6] = studentf;
  105. student[7] = studentg;
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118. Scene scene = new Scene(pane, 1000, 600);
  119. primaryStage.setTitle("asdf");
  120. primaryStage.setScene(scene);
  121. primaryStage.show();
  122.  
  123.  
  124.  
  125. add.setOnAction(new EventHandler<ActionEvent>() {
  126. @Override public void handle(ActionEvent event) {
  127. studCount++;
  128. toWaitArea();
  129. System.out.println("studcount " + studCount);
  130.  
  131. }});
  132.  
  133. next.setOnAction(new EventHandler<ActionEvent>() {
  134. @Override public void handle(ActionEvent event) {
  135. for(int i = 1; i<=studCount; i++){
  136.  
  137. Bounds boundsInScene = student[1].localToScene(student[1].getBoundsInLocal());
  138. nextMove.setToX(boundsInScene.getMaxX()+110);
  139. nextMove.setNode(student[studCount]);
  140. nextMove.play();
  141.  
  142. //assuming that my subjects are the buttons
  143. //if i add 7 buttons and i click next, all 7 should walk straight together but the speed of loop is skipping the animation of each
  144. }
  145.  
  146.  
  147. }});
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155. }
  156.  
  157.  
  158. public void students(){
  159. studenta.setLayoutX(-90);
  160. studenta.setLayoutY(270);
  161. studenta.setPrefWidth(20);
  162. studenta.setPrefHeight(100);
  163. // studenta.setVisible(false);
  164.  
  165.  
  166. studentb.setLayoutX(-90);
  167. studentb.setLayoutY(270); studentb.setPrefWidth(20);
  168. studentb.setPrefHeight(100);
  169. // studentb.setVisible(false);
  170.  
  171.  
  172. studentc.setLayoutX(-90);
  173. studentc.setLayoutY(270);
  174. studentc.setPrefWidth(20);
  175. studentc.setPrefHeight(100);
  176. // studentc.setVisible(false);
  177.  
  178.  
  179. studentd.setLayoutX(-90);
  180. studentd.setLayoutY(270);
  181. studentd.setPrefWidth(20);
  182. studentd.setPrefHeight(100);
  183. // studentd.setVisible(false);
  184.  
  185.  
  186. studente.setLayoutX(-90);
  187. studente.setLayoutY(270);
  188. studente.setPrefWidth(20);
  189. studente.setPrefHeight(100);
  190. // studente.setVisible(false);
  191.  
  192.  
  193. studentf.setLayoutX(-90);
  194. studentf.setLayoutY(270);
  195. studentf.setPrefWidth(20);
  196. studentf.setPrefHeight(100);
  197. // studentf.setVisible(false);
  198.  
  199.  
  200. studentg.setLayoutX(-90);
  201. studentg.setLayoutY(270);
  202. studentg.setPrefWidth(20);
  203. studentg.setPrefHeight(100);
  204. // studentg.setVisible(false);
  205. pane.getChildren().add(studenta);
  206. pane.getChildren().add(studentb);
  207. pane.getChildren().add(studentc);
  208. pane.getChildren().add(studentd);
  209. pane.getChildren().add(studente);
  210. pane.getChildren().add(studentf);
  211. pane.getChildren().add(studentg);
  212. }
  213.  
  214. public void addNew(){
  215. ageWarning.setLayoutX(180);
  216. ageWarning.setLayoutY(540);
  217. ageWarning.setStyle("-fx-text-fill: #ff0a3b; ");
  218. ageWarning.setVisible(false);
  219. pane.getChildren().addAll(ageWarning);
  220.  
  221. ageField.setPrefWidth(50);
  222. ageField.setPrefHeight(40);
  223. ageField.setLayoutX(150);
  224. ageField.setLayoutY(540);
  225. ageField.setPromptText("Age");
  226. ageField.setVisible(false);
  227. pane.getChildren().addAll(ageField);
  228.  
  229. add.setPrefWidth(100);
  230. add.setPrefHeight(40);
  231. add.setLayoutX(40);
  232. add.setLayoutY(540);
  233. add.setCursor(Cursor.OPEN_HAND);
  234. pane.getChildren().addAll(add);
  235.  
  236. vaccinate.setPrefWidth(100);
  237. vaccinate.setPrefHeight(40);
  238. vaccinate.setLayoutX(400);
  239. vaccinate.setLayoutY(540);
  240. vaccinate.setCursor(Cursor.OPEN_HAND);
  241. pane.getChildren().addAll(vaccinate);
  242.  
  243.  
  244. next.setPrefWidth(100);
  245. next.setPrefHeight(40);
  246. next.setLayoutX(550);
  247. next.setLayoutY(540);
  248. next.setCursor(Cursor.OPEN_HAND);
  249. pane.getChildren().addAll(next);
  250.  
  251. noStudents.setLayoutX(480);
  252. noStudents.setLayoutY(540);
  253. noStudents.setStyle("-fx-text-fill: #ff0a3b; ");
  254. noStudents.setVisible(false);
  255. pane.getChildren().addAll(noStudents);
  256.  
  257. none.setPrefWidth(100);
  258. none.setPrefHeight(40);
  259. none.setLayoutX(700);
  260. none.setLayoutY(540);
  261. none.setCursor(Cursor.OPEN_HAND);
  262. pane.getChildren().addAll(none);
  263. }
  264.  
  265. public void toWaitArea(){
  266. if(studCount==1){
  267. student[studCount].setVisible(true);
  268. toWalk1.setToX(700);
  269. toWalk1.setNode(student[studCount]);
  270. toWalk1.play();
  271. }else if(studCount==2){
  272. student[studCount].setVisible(true);
  273. toWalk2.setToX(610);
  274. toWalk2.setNode(student[studCount]);
  275. toWalk2.play();
  276. }else if(studCount==3){
  277. student[studCount].setVisible(true);
  278. toWalk3.setToX(520);
  279. toWalk3.setNode(student[studCount]);
  280. toWalk3.play();
  281. }else if(studCount==4){
  282. student[studCount].setVisible(true);
  283. toWalk4.setToX(430);
  284. toWalk4.setNode(student[studCount]);
  285. toWalk4.play();
  286. }else if(studCount==5){
  287. student[studCount].setVisible(true);
  288. toWalk5.setToX(340);
  289. toWalk5.setNode(student[studCount]);
  290. toWalk5.play();
  291. }else if(studCount==6){
  292. student[studCount].setVisible(true);
  293. toWalk6.setToX(250);
  294. toWalk6.setNode(student[studCount]);
  295. toWalk6.play();
  296. }else if(studCount==7){
  297. student[studCount].setVisible(true);
  298. toWalk7.setToX(160);
  299. toWalk7.setNode(student[studCount]);
  300. toWalk7.play();
  301. }
  302. }
  303.  
  304.  
  305.  
  306.  
  307.  
  308. public static void main(String[] args) {
  309. launch(args);
  310.  
  311. }
  312. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement