title: Sorting numbers from a random method in Java
body: <p>Whenever I click refresh in my program here, it will generate 5 random numbers from between 1 to 13 and display it in the form of cards on screen. I'm using JavaFx for that. I cannot figure out the second thing, which is when I click the Sort button then the program should take the current set of random numbers and show the cards from lowest to highest.</p>
  
  <pre><code>public class Cards extends Application {
  public static void main(String[] args) {
      Application.launch(args);
  
  }
  
  public static int mycard() {
      Random rand = new Random();
      int  n = rand.nextInt(13) + 1;
      return n;
  }
  
  public void start(Stage primaryStage) {
  
      primaryStage.setTitle("Cards Layout");
  
      GridPane pane = new GridPane();
      pane.setAlignment(Pos.CENTER);
      pane.setHgap(10);
      pane.setVgap(5);
  
  
      // creates button
      Button refresh = new Button("Refresh");
      HBox button = new HBox(10);
      button.setAlignment(Pos.BOTTOM_LEFT);
      button.getChildren().add(refresh);
      pane.getChildren().add(refresh);
  
      //Create sort button
      Button sort = new Button("Sort");
      HBox button1 = new HBox(10);
      button1.setAlignment(Pos.BOTTOM_RIGHT);
      button1.getChildren().add(sort);
      pane.getChildren().add(sort);
  
      // creates random card images and adds them to pane
      Image img = new Image("image/card/"+mycard()+".png");
      ImageView imgView = new ImageView(img);
  
      pane.add(imgView, 1, 0);
  
      Image img2 = new Image("image/card/"+mycard() +".png");
      ImageView imgView2 = new ImageView(img2);
      pane.add(imgView2, 2, 0);
  
      Image img3 = new Image("image/card/" +mycard()+ ".png");
      ImageView imgView3 = new ImageView(img3);
      pane.add(imgView3, 3, 0);
  
      Image img4 = new Image("image/card/" +mycard()+".png");
      ImageView imgView4 = new ImageView(img4);
      pane.add(imgView4, 4, 0);
  
      Image img5 = new Image("image/card/" +mycard()+".png");
      ImageView imgView5 = new ImageView(img5);
      pane.add(imgView5, 5, 0);
  
      Scene scene = new Scene(pane, 600, 200);
      primaryStage.setScene(scene);
      primaryStage.show();
      refresh.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
          public void handle(ActionEvent e) {
              imgView.setImage(new Image("image/card/" +mycard()+".png"));
              imgView2.setImage(new Image("image/card/" +mycard()+".png"));
              imgView3.setImage(new Image("image/card/" +mycard()+".png"));
              imgView4.setImage(new Image("image/card/" +mycard()+".png"));
              imgView5.setImage(new Image("image/card/" +mycard()+".png"));
          }
      });
      sort.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
          public void handle(ActionEvent e) {
              imgView.setImage(new Image("image/card/" + "1.png"));
              imgView2.setImage(new Image("image/card/" + "2.png"));
              imgView3.setImage(new Image("image/card/" + "3.png"));
              imgView4.setImage(new Image("image/card/" + "4.png"));
              imgView5.setImage(new Image("image/card/" + "5.png"));
  //Cannot figure out what to do here ^
          }
      });
  
  }
  }
  </code></pre>