Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.52 KB | None | 0 0
  1. package javafx;
  2.  
  3. import java.net.URL;
  4.  
  5. import javafx.application.Application;
  6. import javafx.beans.InvalidationListener;
  7. import javafx.beans.Observable;
  8. import javafx.event.ActionEvent;
  9. import javafx.event.EventHandler;
  10. import javafx.scene.Scene;
  11. import javafx.scene.control.Button;
  12. import javafx.scene.control.Label;
  13. import javafx.scene.control.Slider;
  14. import javafx.scene.image.Image;
  15. import javafx.scene.layout.GridPane;
  16. import javafx.scene.layout.HBox;
  17. import javafx.scene.layout.VBox;
  18. import javafx.scene.media.AudioClip;
  19. import javafx.stage.Stage;
  20.  
  21. public class audio extends Application {
  22. private AudioClip som;
  23.  
  24. public static void main(String[] args) {
  25. Application.launch(args);
  26. }
  27. public void init() {
  28. final URL resource = getClass().getResource("exemplo.mp3");
  29. som = new AudioClip(resource.toExternalForm());
  30. }
  31. public void start(Stage palco) {
  32. Button inicB = new Button(">");
  33. Button sairB = new Button("||");
  34.  
  35. final Slider volume = new Slider(0.0,1.,0.5);
  36. volume.setMajorTickUnit(0.1);
  37. volume.setShowTickLabels(true);
  38.  
  39. inicB.setOnAction(new EventHandler<ActionEvent>() {
  40.  
  41. public void handle(ActionEvent e) {
  42. som.play();
  43. }
  44. });
  45. sairB.setOnAction(new EventHandler<ActionEvent>() {
  46.  
  47. public void handle(ActionEvent e) {
  48. som.stop();
  49. }
  50. });
  51. volume.valueProperty().addListener(new InvalidationListener() {
  52.  
  53. @Override
  54. public void invalidated(Observable observable) {
  55. if(volume.isValueChanging()) {
  56. som.setVolume(volume.getValue());
  57. }
  58.  
  59. }
  60. });
  61. GridPane PainelSlider = new GridPane();
  62.  
  63. PainelSlider.setHgap(5);
  64. PainelSlider.setVgap(10);
  65.  
  66. PainelSlider.addRow(0, new Label("Volume:"), volume);
  67.  
  68. HBox cxBotao = new HBox(5, inicB, sairB);
  69. VBox raiz = new VBox(5,PainelSlider, cxBotao);
  70.  
  71. raiz.setPrefWidth(300);
  72. raiz.setPrefHeight(100);
  73. raiz.setStyle("-fx-padding: 10;"+
  74. "-fx-border-package javafx;
  75.  
  76. import java.net.URL;
  77.  
  78. import javafx.application.Application;
  79. import javafx.beans.InvalidationListener;
  80. import javafx.beans.Observable;
  81. import javafx.event.ActionEvent;
  82. import javafx.event.EventHandler;
  83. import javafx.scene.Scene;
  84. import javafx.scene.control.Button;
  85. import javafx.scene.control.Label;
  86. import javafx.scene.control.Slider;
  87. import javafx.scene.image.Image;
  88. import javafx.scene.layout.GridPane;
  89. import javafx.scene.layout.HBox;
  90. import javafx.scene.layout.VBox;
  91. import javafx.scene.media.AudioClip;
  92. import javafx.stage.Stage;
  93.  
  94. public class audio extends Application {
  95. private AudioClip som;
  96.  
  97. public static void main(String[] args) {
  98. Application.launch(args);
  99. }
  100. public void init() {
  101. final URL resource = getClass().getResource("exemplo.mp3");
  102. som = new AudioClip(resource.toExternalForm());
  103. }
  104. public void start(Stage palco) {
  105. Button inicB = new Button(">");
  106. Button sairB = new Button("||");
  107.  
  108. final Slider volume = new Slider(0.0,1.,0.5);
  109. volume.setMajorTickUnit(0.1);
  110. volume.setShowTickLabels(true);
  111.  
  112. inicB.setOnAction(new EventHandler<ActionEvent>() {
  113.  
  114. public void handle(ActionEvent e) {
  115. som.play();
  116. }
  117. });
  118. sairB.setOnAction(new EventHandler<ActionEvent>() {
  119.  
  120. public void handle(ActionEvent e) {
  121. som.stop();
  122. }
  123. });
  124. volume.valueProperty().addListener(new InvalidationListener() {
  125.  
  126. @Override
  127. public void invalidated(Observable observable) {
  128. if(volume.isValueChanging()) {
  129. som.setVolume(volume.getValue());
  130. }
  131.  
  132. }
  133. });
  134. GridPane PainelSlider = new GridPane();
  135.  
  136. PainelSlider.setHgap(5);
  137. PainelSlider.setVgap(10);
  138.  
  139. PainelSlider.addRow(0, new Label("Volume:"), volume);
  140.  
  141. HBox cxBotao = new HBox(5, inicB, sairB);
  142. VBox raiz = new VBox(5,PainelSlider, cxBotao);
  143.  
  144. raiz.setPrefWidth(300);
  145. raiz.setPrefHeight(100);
  146. raiz.setStyle("-fx-padding: 10;"+
  147. "-fx-border-style: solid inside;"+
  148. "-fx-border-width: 2;"+
  149. "-fx-border-insets: 5;"+
  150. "-fx-border-radois: 5;"+
  151. "-fx-border-color: red;");
  152.  
  153. palco.getIcons().add(new Image("file:///Users/teresacosta/M10/javafx/bin/javafx/som.png"));
  154. Scene cena = new Scene(raiz);
  155.  
  156. palco.setScene(cena);
  157. palco.setTitle("SOM");
  158. palco.show();
  159. }
  160. }
  161. style: solid inside;"+
  162. "-fx-border-width: 2;"+
  163. "-fx-border-insets: 5;"+
  164. "-fx-border-radius: 5;"+
  165. "-fx-border-color: red;");
  166.  
  167. palco.getIcons().add(new Image("file:///Users/teresacosta/M10/javafx/bin/javafx/som.png"));
  168. Scene cena = new Scene(raiz);
  169.  
  170. palco.setScene(cena);
  171. palco.setTitle("SOM");
  172. palco.show();
  173. }
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement