Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

give a brief synopsis of what the problem is and does. Describe the JavaFX UI Co

ID: 3827951 • Letter: G

Question

give a brief synopsis of what the problem is and does.

Describe the JavaFX UI Controls present in the program (some are games while others are utilities).

Tell us how some of these small programs relate to features found in some commercial games or applications you have seen and possibly used.

I am looking for an analysis covering the questions above. This is not intended to take hours and I do not expect to see code or pages of typed text. I want you to draw connections to Chapter(s) Content and assignments the Author feels you should be able to code verbally.

Exercise 16 21 30 Exercise 16 21 29 Exercise 16.20 alxu Exercise 16 20 Olx Exercise16 21 00:00:00 00:00:15 00:00:06 28 Pause dear Resume dear Start gear (c) (a) (d) (b) FIGURE 16.45 (a-c) The program counts up the time. (d) The program counts down the time. *16.21 (Count-down stopwatch) Write a program that allows the user to enter time in seconds in the text field and press the Enter key to count down the seconds, as shown in Figure 16.45d. The remaining seconds are redisplayed every one second. When the seconds are expired, the program starts to play music continuously. O

Explanation / Answer

//Count_down_stopwatch.java

import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import javafx.util.Duration;


public class Count_down_stopwatch extends Application {

private MediaPlayer mediaPlayer;
private TextField textField;
private int count;

public static void main(String[] args) {
Application.launch(args);
}

@Override
public void start(Stage primaryStage) {
initializeMediaPlayer();
Scene scene = new Scene(getTextPane());
primaryStage.setTitle("Exercise");
primaryStage.setScene(scene);
primaryStage.show();
}

private Pane getTextPane() {
textField = new TextField();
textField.setFont(Font.font(50));
textField.setPrefWidth(300);
textField.setAlignment(Pos.CENTER);
textField.setOnAction(event -> startCountdown(textField.getText()));
return new StackPane(textField);
}

private void initializeMediaPlayer() {
Media music = new Media(
"http://cs.armstrong.edu/liang/common/audio/anthem/anthem6.mp3");
mediaPlayer = new MediaPlayer(music);
mediaPlayer.setCycleCount(MediaPlayer.INDEFINITE);
}

private void startCountdown(String number) {
try {
mediaPlayer.stop();
textField.setPromptText(null);
count = (int) Double.parseDouble(number);
KeyFrame keyFrame = new KeyFrame(
Duration.millis(1000), event -> updateTextField());
Timeline timeline = new Timeline(keyFrame);
timeline.setCycleCount(count);
timeline.play();
} catch (NumberFormatException e) {
textField.setPromptText("Error");
}
}

private void updateTextField() {
count--;
textField.setText(count + "");
if (count == 0) {
mediaPlayer.play();
}
}
}