Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Lab #5 - 14.3
- import javafx.application.Application;
- import javafx.scene.Scene;
- import javafx.scene.layout.HBox;
- import javafx.scene.layout.Pane;
- import javafx.geometry.Insets;
- import javafx.stage.Stage;
- import javafx.scene.image.Image;
- import javafx.scene.image.ImageView;
- public class ShowImage extends Application {
- @Override // Override the start method in the Application class
- public void start(Stage primaryStage) {
- // Create a pane to hold the image views
- Pane pane = new HBox(10);
- pane.setPadding(new Insets(5, 5, 5, 5));
- int rand = (int)(Math.random() * 52 + 1);
- Image image = new Image(rand+".png");
- pane.getChildren().add(new ImageView(image));
- int rand2 = (int)(Math.random() * 52 + 1);
- Image image2 = new Image(rand2+".png");
- while(image == image2) {
- int x = (int)(Math.random() * 52 + 1);
- image2 = new Image(x+".png");
- }
- pane.getChildren().add(new ImageView(image2));
- int rand3 = (int)(Math.random() * 52 + 1);
- Image image3 = new Image(rand3+".png");
- while(image == image3 || image2 == image3) {
- int x = (int)(Math.random() * 52 + 1);
- image3 = new Image(x+".png");
- }
- pane.getChildren().add(new ImageView(image3));
- // Create a scene and place it in the stage
- Scene scene = new Scene(pane);
- primaryStage.setTitle("ShowImage"); // Set the stage title
- primaryStage.setScene(scene); // Place the scene in the stage
- primaryStage.show(); // Display the stage
- }
- /**
- * The main method is only needed for the IDE with limited
- * JavaFX support. Not needed for running from the command line.
- */
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement