Advertisement
RazorBlade57

Lab 5

Apr 8th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.77 KB | None | 0 0
  1. //Lab #5 - 14.3
  2.  
  3. import javafx.application.Application;
  4. import javafx.scene.Scene;
  5. import javafx.scene.layout.HBox;
  6. import javafx.scene.layout.Pane;
  7. import javafx.geometry.Insets;
  8. import javafx.stage.Stage;
  9. import javafx.scene.image.Image;
  10. import javafx.scene.image.ImageView;
  11.  
  12. public class ShowImage extends Application {
  13.   @Override // Override the start method in the Application class
  14.   public void start(Stage primaryStage) {
  15.     // Create a pane to hold the image views
  16.     Pane pane = new HBox(10);
  17.     pane.setPadding(new Insets(5, 5, 5, 5));
  18.    
  19.     int rand = (int)(Math.random() * 52 + 1);
  20.    
  21.     Image image = new Image(rand+".png");
  22.     pane.getChildren().add(new ImageView(image));
  23.    
  24.     int rand2 = (int)(Math.random() * 52 + 1);
  25.     Image image2 = new Image(rand2+".png");
  26.    
  27.     while(image == image2) {
  28.         int x = (int)(Math.random() * 52 + 1);
  29.         image2 = new Image(x+".png");
  30.     }
  31.    
  32.     pane.getChildren().add(new ImageView(image2));
  33.    
  34.     int rand3 = (int)(Math.random() * 52 + 1);
  35.     Image image3 = new Image(rand3+".png");
  36.    
  37.     while(image == image3 || image2 == image3) {
  38.         int x = (int)(Math.random() * 52 + 1);
  39.         image3 = new Image(x+".png");
  40.     }
  41.    
  42.     pane.getChildren().add(new ImageView(image3));
  43.    
  44.    
  45.    
  46.     // Create a scene and place it in the stage
  47.     Scene scene = new Scene(pane);
  48.     primaryStage.setTitle("ShowImage"); // Set the stage title
  49.     primaryStage.setScene(scene); // Place the scene in the stage
  50.     primaryStage.show(); // Display the stage
  51.   }
  52.  
  53.   /**
  54.    * The main method is only needed for the IDE with limited
  55.    * JavaFX support. Not needed for running from the command line.
  56.    */
  57.   public static void main(String[] args) {
  58.     launch(args);
  59.   }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement