Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. package sample;
  2.  
  3. import javafx.fxml.FXML;
  4. import javafx.scene.control.Button;
  5. import javafx.scene.control.Label;
  6. import javafx.scene.control.TextArea;
  7. import javafx.scene.control.TextField;
  8. import javafx.scene.image.Image;
  9. import javafx.scene.image.ImageView;
  10.  
  11. import java.io.FileInputStream;
  12. import java.io.FileNotFoundException;
  13.  
  14. public class Controller {
  15.  
  16. @FXML
  17. Button buttonNext;
  18.  
  19. @FXML
  20. Button buttonPrevious;
  21.  
  22. @FXML
  23. ImageView imageView;
  24.  
  25. int currentImageIndex = 2;
  26.  
  27. @FXML
  28. public void initialize() throws Exception {
  29. FileInputStream inputStream = new FileInputStream("images\\1.jpg");
  30. imageView.setImage(new Image(inputStream));
  31.  
  32. buttonNext.setOnAction((event -> {
  33. System.out.println(currentImageIndex);
  34. if (currentImageIndex < 5) {
  35. String fileName = "images\\" + currentImageIndex + ".jpg";
  36. currentImageIndex++;
  37. try {
  38. FileInputStream temp = new FileInputStream(fileName);
  39. imageView.setImage(new Image(temp));
  40. } catch (FileNotFoundException e) {
  41. }
  42. }
  43. }));
  44.  
  45. buttonPrevious.setOnAction((event -> {
  46. System.out.println(currentImageIndex);
  47. if (currentImageIndex >= 1) {
  48. String fileName = "images\\" + currentImageIndex + ".jpg";
  49. currentImageIndex--;
  50. try {
  51. FileInputStream temp = new FileInputStream(fileName);
  52. imageView.setImage(new Image(temp));
  53. } catch (FileNotFoundException e) {
  54. }
  55. }
  56. }));
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement