| Exercise16_21 1미지 30 | Exercise16_21 29 | Exercise16_21 28 (d) х

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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 d . The remaining seconds are redisplayed
every second.
When the seconds are expired, the program starts to play music
continuously.

| Exercise16_21
1미지
30
| Exercise16_21
29
| Exercise16_21
28
(d)
х
Transcribed Image Text:| Exercise16_21 1미지 30 | Exercise16_21 29 | Exercise16_21 28 (d) х
Expert Solution
Step 1

Program:

/*Import necessary packages into program*/

import java.io.File;

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.media.Media;

import javafx.scene.media.MediaPlayer;

import javafx.scene.text.Font;

import javafx.stage.Stage;

import javafx.util.Duration;

//Class definition

public class Exercise16_21 extends Application

{

     /*Object definition for “textfield”*/

     TextField txtsec = new TextField();

     /*Object definition for Timeline*/

     Timeline aniTimeline = new Timeline(

new KeyFrame(Duration.millis(1000), e ->

{

int seconds = Integer.parseInt(txtsec.getText());

txtsec.setText(seconds - 1 + "");

if (seconds - 1 <= 0)

{

stopAnimation();

}

}));

     //Define the music file into variable

String bip="C:\\Users\\Public\\Music\\Sample Music\\Kalimba.mp3";

     //Define the object for "Media"

Media media = new Media(new File(bip).toURI().toString());

     //Define the object for "MediaPlayer"

     MediaPlayer mp = new MediaPlayer(media);

     /*Method definition for application*/

     public void start(Stage primaryStage)

{

          /*Define the count for timeline*/

          mp.setCycleCount(Timeline.INDEFINITE);

          /*Define the cycle count*/

          aniTimeline.setCycleCount(Timeline.INDEFINITE);

          /*Define alignment for text field*/

          txtsec.setAlignment(Pos.CENTER);

          /*Define alignment for text second*/

          txtsec.setOnAction(e -> {

               /*Playing the animation*/

               aniTimeline.play();

          });

          //Set the font for text field

          txtsec.setFont(Font.font("Times", 35));

          /*Define the "Scene" for text field*/

          Scene scene = new Scene(txtsec, 200, 100);

          /*Set the title for aplication*/

          primaryStage.setTitle("Exercise16_21");

          /*Set the Scene*/

          primaryStage.setScene(scene);

          //Display the application

          primaryStage.show();

     }

     /*Method definition for stop the animation*/

     private void stopAnimation()

{

          //Stop the animation

          aniTimeline.stop();

          //Play the animation

          mp.play();

     }

     //Main method

     public static void main(String[] args)

     {

          /*Launch the application*/

          launch(args);

     }

}

Step 2

Output:

Computer Science homework question answer, step 2, image 1 

Computer Science homework question answer, step 2, image 2

Computer Science homework question answer, step 2, image 3

  • If the timer reaches “0”, it plays the “mp3” music which is mentioned on code.
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Basics of loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education