Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here is what I have so far but I can\'t seem to get how to make these random car

ID: 3639557 • Letter: H

Question

Here is what I have so far but I can't seem to get how to make these random cards. Everytime I start putting in the random function I get tons of errors and can't figure out where to go from here.

package RandomCards;
// best test yet, now need to make the cards random and you are almost there.
import javax.swing.*;
import java.awt.*;

public class Cards extends JFrame {

// private static final long serialVersionUID = 1L;


private static final long serialVersionUID = 1L;

public static void main(String[] args) {

Cards frame = new Cards();
frame.setTitle("Cards");
frame.setSize(500, 200);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}


private ImageIcon Card1 = new ImageIcon("card/5.png");
private ImageIcon Card2 = new ImageIcon("card/18.png");
private ImageIcon Card3 = new ImageIcon("card/31.png");
private ImageIcon Card4 = new ImageIcon("card/43.png");
private ImageIcon Card5 = new ImageIcon("card/30.png");

public Cards(){
setLayout(new GridLayout(1, 4, 5, 5));
add(new JLabel(Card1));
add(new JLabel(Card2));
add(new JLabel(Card3));
add(new JLabel(Card4));
add(new JLabel(Card5));
}


}

Explanation / Answer

Code for selecting 3 random cards... you can cahnge the number based on how many you need in your code.