Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sample;
- import javafx.fxml.FXML;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.TextArea;
- import javafx.scene.control.TextField;
- import javafx.scene.image.Image;
- import javafx.scene.image.ImageView;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- public class Controller {
- @FXML
- Button buttonNext;
- @FXML
- Button buttonPrevious;
- @FXML
- ImageView imageView;
- int currentImageIndex = 2;
- @FXML
- public void initialize() throws Exception {
- FileInputStream inputStream = new FileInputStream("images\\1.jpg");
- imageView.setImage(new Image(inputStream));
- buttonNext.setOnAction((event -> {
- System.out.println(currentImageIndex);
- if (currentImageIndex < 5) {
- String fileName = "images\\" + currentImageIndex + ".jpg";
- currentImageIndex++;
- try {
- FileInputStream temp = new FileInputStream(fileName);
- imageView.setImage(new Image(temp));
- } catch (FileNotFoundException e) {
- }
- }
- }));
- buttonPrevious.setOnAction((event -> {
- System.out.println(currentImageIndex);
- if (currentImageIndex >= 1) {
- String fileName = "images\\" + currentImageIndex + ".jpg";
- currentImageIndex--;
- try {
- FileInputStream temp = new FileInputStream(fileName);
- imageView.setImage(new Image(temp));
- } catch (FileNotFoundException e) {
- }
- }
- }));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement