Question

Please write a simple Slideshow program in Java GUI. There are three buttons in the bottom...

Please write a simple Slideshow program in Java GUI.

There are three buttons in the bottom Panel.

Open: you can choose multiple pictures.

Start: starts the slideshow and change the picture in two seconds.

Stop: you can stop the slideshow.

0 0
Add a comment Improve this question Transcribed image text
Answer #1


Please let me know if you have any doubts or you want me to modify the answer. And if you find this answer useful then don't forget to rate my answer as thumps up. Thank you! :)

import javafx.animation.Animation;
import javafx.application.Application;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.scene.image.ImageView;
import java.util.ArrayList;
import java.io.File;
import javafx.util.Duration;
public class SlideShow extends Application {
    private int currentImage = 1;
    ArrayList<Scene> scenes = new ArrayList<Scene>(0);


    public void start(Stage primaryStage) throws InterruptedException{

        EventHandler<ActionEvent> eventHandler = e -> {
            if (currentImage >= scenes.size()){
                currentImage = 0;
                System.out.println("looping back to the beginning");
            }
            primaryStage.setScene(scenes.get(currentImage++));
            System.out.println("Displaying image no. " + currentImage);
        };

        Timeline slideShow = new Timeline(new KeyFrame(Duration.seconds(2), eventHandler));

        File imageDirectory = new File("/Users/swapnil/IdeaProjects/SlideShow/src/Image");
        for (String image : imageDirectory.list()){

            StackPane tempStack = new StackPane(new ImageView("image/"+image));
            Scene tempScene = new Scene(tempStack);
            tempScene.setOnMouseClicked(e -> {
                System.out.println("Mouse Clicked");
                if (slideShow.getStatus() == Animation.Status.PAUSED){
                    slideShow.play();
                    System.out.println("Playing slideshow");
                }
                else{
                    slideShow.pause();
                    System.out.println("Pausing slideshow");
                }
            });
            scenes.add(tempScene);
        }


        slideShow.setCycleCount(Timeline.INDEFINITE);
        slideShow.play();
        primaryStage.setTitle("Flag Slide Show");
        primaryStage.setScene(scenes.get(0));
        primaryStage.show();
    }


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


}

Add a comment
Know the answer?
Add Answer to:
Please write a simple Slideshow program in Java GUI. There are three buttons in the bottom...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program to play "Three Button Monte." Your program should draw three buttons labeled "Door...

    Write a program to play "Three Button Monte." Your program should draw three buttons labeled "Door 1' " " Door 2' " and "Door 3" in a window and randomly select one of the buttons (without telling the user which one is selected) . The program then prompts the user to click on one of the buttons. A click on the special button is a win, and a click on one of the other two is a loss. You should...

  • Using Java, please design the GUI in the following prompt. PLEASE TEST YOUR PROGRAM. Thanks! Write...

    Using Java, please design the GUI in the following prompt. PLEASE TEST YOUR PROGRAM. Thanks! Write a program that displays three buttons with the names or images of three candidates for public of office. Imagine that a person votes by clicking the button that shows the candidate of his/her choice. Display the current number of votes above each button. Include a Finished button that erases the images of the losers and displays only the winner's image with a message of...

  • Need help on following Java GUI problem: Write a program that lets a user display and...

    Need help on following Java GUI problem: Write a program that lets a user display and modify pictures. Create a window. Add four buttons so that clicking a particular button will shift the image by a small amount in the north, south, east or west direction inside the window. Add a menu bar with two menus: File and Image. The File menu should contain an Open menu item that the user can select to display JPEG and PNG files from...

  • JAVASCRIPT Write a GUI application that has three labels, two text fields, and two buttons (with...

    JAVASCRIPT Write a GUI application that has three labels, two text fields, and two buttons (with the titles Name and Age). When the program starts the user will enter his/her first name in the first text field and his age in the second text field. When the user clicks the Name button, the first name entered by the user will be displayed as a separate label with the words "CSC210 student at the back of it. When the user clicks...

  • In Java, please write the program for the following program. Please TEST YOUR PROGRAM. You MUST...

    In Java, please write the program for the following program. Please TEST YOUR PROGRAM. You MUST use GUI, that means all user input must be through the windows. The "first window" is the window on the top left of the following picture. Add 5 more items to be purchased. Search is accessed from second window, top right. Thw third window is the bottom left, and the fourth window is the bottom right. The program MUST CONTAIN EVERYTHING IN THE PICTURES....

  • Nork individually or in pairs to write a simple "timer" dialog in Java. The dialog shall...

    Nork individually or in pairs to write a simple "timer" dialog in Java. The dialog shall consist of three GUI components: a text field co display the elapse time in the hh:mm:ss format and start/stop puttons to start and stop the timer (see the lecture notes for sample screenshots). As suggested in the lecture notes, separate the model (TimerModel) From the view and control (TimerDialog) to make the model reusable. Ir Eact, you will reuse the model class when you...

  • java # 5 (to be finished later) Develop at application with GUI that will be calculating...

    java # 5 (to be finished later) Develop at application with GUI that will be calculating volume of a cylinder in cubic centimeters (see Day 2, practice exercise 2 and feel free to use the program you worked on). 1) Start with the layout. Plan the entry field, plan the buttons layout. Feel free to use this picture (to make it more appealing to the user): eds.l

  • Write a java program that demonstrates recursion. This program can be in a java GUI frame...

    Write a java program that demonstrates recursion. This program can be in a java GUI frame or as a console application. On this one it is up to you. (It would probably work better as a console program for this particular program.) The input for this program is a number of boxes. Ask the user for this with a textbox or a prompt on the command line. Demonstrate recursion with a function called LoadTruck() that takes a number of boxes...

  • Using Java develop a GUI based simple quiz game. The questions and answers of the game...

    Using Java develop a GUI based simple quiz game. The questions and answers of the game will be stored in a text file (i.e. our database). On the first page the users will be provided with some instructions on how to play the game and next button to go to the next page. On the next page will be a start button to either start the game and an exit button to exit the game. Once the game starts there...

  • Using Java, please create the program for the following prompt. MUST CREATE BUTTONS IN A JFRAME,...

    Using Java, please create the program for the following prompt. MUST CREATE BUTTONS IN A JFRAME, as specified by the prompt! DO NOT use user input of 1, 2, 3 etc. User input must come from clicking the buttons. Please be sure to test your program. Thank you! Write a program that displays three buttons with the names or images of three candidates for public of office. Imagine that a person votes by clicking the button that shows the candidate...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT