目录
题目:**16.26(模拟:升旗并播放国歌)
习题思路:
代码示例
结果展示
音频来源
题目:**16.26(模拟:升旗并播放国歌)
创建一个显示升国旗的程序,如图15-14所示。随着国旗的升起,播放国歌(可以使用程序清单16- 8中的国旗图像和国歌音频文件)。
-
习题思路:
- 可以改写程序清单15.13,创建一个AudioClip,在动画开始时播放音频
-
代码示例
编程练习题16_26PlayNationalAnthem.java
package chapter_16;
import javafx.animation.PathTransition;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.media.AudioClip;
import javafx.scene.shape.Line;
import javafx.stage.Stage;
import javafx.util.Duration;
public class 编程练习题16_26PlayNationalAnthem extends Application{
@Override
public void start(Stage primaryStage) throws Exception {
Pane pane = new Pane();
AudioClip audioClip = new AudioClip("file:/C:/Users/Lenovo/eclipse-workspace/JavaFX/src/Music/义勇军进行曲.mp3");
ImageView imageView = new ImageView("src/Image/China.png");
pane.getChildren().add(imageView);
PathTransition pt = new PathTransition(Duration.millis(10000),
new Line(300, 800, 300, 0),imageView);
pt.setCycleCount(5);
pt.play();
audioClip.play();
Scene scene = new Scene(pane,950, 1000);
primaryStage.setTitle("编程练习题16_26PlayNationalAnthem");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
结果展示
音频来源:
https://pan.baidu.com/s/16ivb41cTqsQgUGsK5htjFQ提取码:4ky5