jeudi 23 février 2017

Display 3 Random Cards JavaFX

So basically the challenge is in the title. It's pretty basic but I think I have most of it. The one problem I am having is that the place from which the pictures of the cards are coming from. i know that usually you have them coming from your computer, but I am doing it where the pics are coming from an web URL. This is what i have so far but I am getting a host of errors(InvocationTargetException, Runtime, and IndexOutOfBounds) Any help is appreciated.

   import java.util.ArrayList;
   import javafx.application.Application;
   import javafx.stage.Stage;
   import javafx.scene.Scene;
   import javafx.scene.image.ImageView;
   import javafx.scene.image.Image;
   import javafx.scene.layout.HBox;
public class Exercise14_03 extends Application{
@Override
public void start(Stage primaryStage){
    ArrayList<String> cards = new ArrayList<>();

    for(int i = 0; i < 52; i++){
        cards.add(String.valueOf(i + 1));

    java.util.Collections.shuffle(cards);

    ImageView view1 = new ImageView(new Image("http://ift.tt/2lzq3yx" + cards.get(0) + ".png"));
    ImageView view2 = new ImageView(new Image("http://ift.tt/2lzq3yx" + cards.get(1) + ".png"));
    ImageView view3 = new ImageView(new Image("http://ift.tt/2lzq3yx" + cards.get(2) + ".png"));

    HBox root = new HBox();

    root.getChildren().add(view1);
    root.getChildren().add(view2);
    root.getChildren().add(view3);

    Scene scene = new Scene(root);

    primaryStage.setTitle("Exercise14_03");
    primaryStage.setScene(scene);
    primaryStage.show();
    }
}

public static void main(String[] args){
    launch(args);
}

}




Aucun commentaire:

Enregistrer un commentaire