/home/caleb/ASDV-Java/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/ThreeRandomCards.java |
package mp1_fx_calebfontenot;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class ThreeRandomCards extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
GridPane pane = new GridPane();
pane.setOnMouseClicked(e -> {
addCards(pane);
});
System.out.println("Created GridPane. Executing addCards() to add cards to GridPane.");
addCards(pane);
Scene scene = new Scene(pane);
primaryStage.setTitle("Three Random Cards");
primaryStage.setScene(scene);
primaryStage.show();
}
public void addCards(GridPane imagePane) {
System.out.println("addCards() executed!");
imagePane.setAlignment(Pos.CENTER);
imagePane.setHgap(5);
imagePane.setVgap(5);
int rand = 0;
for (int i = 0; i < 3; i++) {
rand = (int) ((Math.random() * 54) + 1);
imagePane.add(new ImageView(new Image("https://files.calebfontenot.com/image/card/" + rand + ".png")), i, 0);
System.out.println("added image " + rand + " to the imagePane.");
}
}
public static void main(String[] args) {
launch(args);
}
}