The card files are named 1.png, 2.png,..., 54.png . All three cards are distinct
ID: 3620328 • Letter: T
Question
The card files are named 1.png, 2.png,..., 54.png . All three cards are distinct and selected randomly.This is what I have so far and it displays the cards above but I'm having trouble on displaying the cards randomly each time that the program is run. Please help me. import javax.swing.*;
import java.awt.*;
public class Exercise12_09 extends JFrame{
public static void main (String[] args){
Exercise12_09 frame = new Exercise12_09();
frame.setTitle("Cards");
frame.setSize(300,200);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
private ImageIcon Card1 = new ImageIcon("C:/Users/Shantall/Documents/1.png");
private ImageIcon Card2 = new ImageIcon("C:/Users/Shantall/Documents/38.png");
private ImageIcon Card3 = new ImageIcon("C:/Users/Shantall/Documents/16.png");
public Exercise12_09(){
setLayout(new GridLayout(1,4,5,5));
add(new JLabel(Card1));
add(new JLabel(Card2));
add(new JLabel(Card3));
}
} import javax.swing.*;
import java.awt.*;
public class Exercise12_09 extends JFrame{
public static void main (String[] args){
Exercise12_09 frame = new Exercise12_09();
frame.setTitle("Cards");
frame.setSize(300,200);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
private ImageIcon Card1 = new ImageIcon("C:/Users/Shantall/Documents/1.png");
private ImageIcon Card2 = new ImageIcon("C:/Users/Shantall/Documents/38.png");
private ImageIcon Card3 = new ImageIcon("C:/Users/Shantall/Documents/16.png");
public Exercise12_09(){
setLayout(new GridLayout(1,4,5,5));
add(new JLabel(Card1));
add(new JLabel(Card2));
add(new JLabel(Card3));
}
}
Explanation / Answer
Dear.. Am giving you the sample snippet. Random rnd = new Random(); for (int i = 0; i < 3; i++) { // Set swapWithPos a random position such that 0Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.