Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.72 KB | None | 0 0
  1.  
  2.  
  3. package giereczka2;
  4.  
  5. import javafx.event.Event;
  6. import javafx.event.EventHandler;
  7. import javafx.scene.Scene;
  8. import javafx.scene.control.Button;
  9. import javafx.scene.image.Image;
  10. import javafx.scene.layout.AnchorPane;
  11. import javafx.scene.layout.Background;
  12. import javafx.scene.layout.BackgroundImage;
  13. import javafx.scene.layout.BackgroundPosition;
  14. import javafx.scene.layout.BackgroundRepeat;
  15. import javafx.stage.Stage;
  16. import javafx.scene.image.ImageView;
  17. import javafx.scene.media.Media;
  18. import javafx.scene.media.MediaPlayer;
  19. import javafx.stage.Stage;
  20. import javafx.scene.SubScene;
  21.  
  22.  
  23.  
  24.  
  25. public class widok {
  26. private static final int HEIGHT = 786;
  27. private static final int WIDTH = 1024;
  28. private AnchorPane mainPane;
  29. private Scene mainScene;
  30. private Stage mainStage;
  31. private final String StartPrzycisk = "-fx-background-color: transparent; -fx-graphic: url('resouces/START.png');";
  32. private final String JakGracPrzycisk = "-fx-background-color: transparent; -fx-graphic: url('resouces/JakGrac.png');";
  33. private final String RankingPrzycisk = "-fx-background-color: transparent; -fx-graphic: url('resouces/Ranking.png');";
  34. private final String WyjsciePrzycisk = "-fx-background-color: transparent; -fx-graphic: url('resouces/wyjscie.png');";
  35. private final String DzwiekPrzycisk = "-fx-background-color: transparent; -fx-graphic: url('resouces/dzwiek.png');";
  36. private final String MuzykaPrzycisk = "-fx-background-color: transparent; -fx-graphic: url('resouces/muzyka.png');";
  37. //private ZywieniowePotyczkiStart startSubscene;
  38. private GraSubscene startSubscene;
  39. private GraSubscene jakgracSubscene;
  40. private GraSubscene rankingSubscene;
  41. private GraSubscene wyjscieSubscene;
  42.  
  43. public widok()
  44. {
  45. mainPane = new AnchorPane();
  46. mainScene = new Scene(mainPane,WIDTH,HEIGHT);
  47. mainStage = new Stage();
  48. mainStage.setScene(mainScene);
  49. //mainStage.setResizable(false);
  50. // nie umiem inaczej tego napisac
  51. mainStage.setMinWidth(1024);
  52. mainStage.setMaxWidth(1024);
  53. mainStage.setMinHeight(786);
  54. mainStage.setMaxHeight(786);
  55. createButtons();
  56. createBackground();
  57. createLogo();
  58. createSubScenes();
  59.  
  60. /*sprawdzenie działania subscene
  61. GraSubscene subScene = new GraSubscene();
  62. subScene.setLayoutX(100);
  63. subScene.setLayoutY(100);
  64. mainPane.getChildren().add(subScene);*/
  65.  
  66. }
  67.  
  68. private void createSubScenes() {
  69. startSubscene = new GraSubscene();
  70. mainPane.getChildren().add(startSubscene);
  71.  
  72. jakgracSubscene = new GraSubscene();
  73. mainPane.getChildren().add(jakgracSubscene);
  74.  
  75. rankingSubscene = new GraSubscene();
  76. mainPane.getChildren().add(rankingSubscene);
  77.  
  78. wyjscieSubscene = new GraSubscene();
  79. mainPane.getChildren().add(wyjscieSubscene);
  80. }
  81.  
  82. public Stage getMainStage(){
  83. return mainStage;
  84. }
  85.  
  86.  
  87. public void createButtons() {
  88.  
  89. Button button = new Button();
  90. button.setLayoutX(402);
  91. button.setLayoutY(200);
  92. button.setStyle(StartPrzycisk);
  93.  
  94. Button jakgrac = new Button();
  95. jakgrac.setLayoutX(337);
  96. jakgrac.setLayoutY(300);
  97. jakgrac.setStyle(JakGracPrzycisk);
  98.  
  99. Button ranking = new Button();
  100. ranking.setLayoutX(359);
  101. ranking.setLayoutY(400);
  102. ranking.setStyle(RankingPrzycisk);
  103.  
  104. Button wyjscie = new Button();
  105. wyjscie.setLayoutX(363);
  106. wyjscie.setLayoutY(500);
  107. wyjscie.setStyle(WyjsciePrzycisk);
  108.  
  109. Button dzwiek = new Button();
  110. dzwiek.setLayoutX(84);
  111. dzwiek.setLayoutY(15);
  112. dzwiek.setStyle(DzwiekPrzycisk);
  113.  
  114. Button muzyka = new Button();
  115. muzyka.setLayoutX(10);
  116. muzyka.setLayoutY(10);
  117. muzyka.setStyle(MuzykaPrzycisk);
  118.  
  119. //subscene obsługa przycisków
  120.  
  121.  
  122. mainPane.getChildren().add(button);
  123. mainPane.getChildren().add(jakgrac);
  124. mainPane.getChildren().add(ranking);
  125. mainPane.getChildren().add(wyjscie);
  126. mainPane.getChildren().add(dzwiek);
  127. mainPane.getChildren().add(muzyka);
  128.  
  129. button.setOnMouseClicked(new EventHandler<Event>() {
  130. @Override
  131. public void handle(Event event){
  132. startSubscene.moveSubScene();
  133. }
  134. });
  135.  
  136.  
  137.  
  138. }
  139. private void createBackground() {
  140. Image backgroundImage = new Image("resouces/tlo.png",1024,786,false,true);
  141. BackgroundImage background = new BackgroundImage(backgroundImage, BackgroundRepeat.REPEAT, BackgroundRepeat.REPEAT, BackgroundPosition.DEFAULT, null);
  142. mainPane.setBackground(new Background(background));
  143.  
  144.  
  145. }
  146.  
  147. private void createLogo(){
  148. ImageView logo = new ImageView("resouces/Logo.png");
  149. logo.setLayoutX(101);
  150. logo.setLayoutY(75);
  151.  
  152.  
  153. mainPane.getChildren().add(logo);
  154. }
  155.  
  156. /*public void start(Button muzyka){
  157.  
  158. muzyka.setOnMouseClicked(new EventHandler<Event>() {
  159. @Override
  160. public void handle(Event event){
  161. mediaplayer.play();
  162. System.out.print("Nasz tekst");
  163. }
  164. });
  165.  
  166. Media MusicFile = new Media(getClass().getResource("resources/music.mp3").toExternalForm());
  167.  
  168. mediaplayer = new MediaPlayer(MusicFile);
  169. mediaplayer.setAutoPlay(true);
  170. mediaplayer.setVolume(0.1);
  171. mainPane.getChildren().addAll(muzyka);
  172. }
  173. */ // kiedyś może to się przyda
  174.  
  175.  
  176.  
  177.  
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement