hey guys im trying to get my code to display 3 random cards from my images folder ( the cards are labeled 1.png to 54.png). Im confused how i would get my program to read and display my cards.
im confused it is giving me an error at ukicon = new imageIcon... basically its telling me to put a } after my semicolon.import javax.swing.*; import java.awt.*; import java.util.*; public class DisplayCard extends JFrame { String[] images; for (int i = 1; i < 0 && i >=54;i++) { images[i] = i+".png"; } Random rn = new Random(); int maximum = 54; int minimum = 1; int range = maximum - minimum + 1; int randomNum = rn.nextInt(range) + minimum; protected ImageIcon usIcon = new ImageIcon(images[randomNum]); protected ImageIcon myIcon = new ImageIcon(images[randomNum]); protected ImageIcon frIcon = new ImageIcon(images[randomNum]); protected ImageIcon ukIcon = new ImageIcon(images[randomNum]); public DisplayCard() { setLayout(new GridLayout(1, 4, 5, 5)); add(new JLabel(usIcon)); add(new JLabel(myIcon)); add(new JButton(frIcon)); add(new JButton(ukIcon)); } /** Main method */ public static void main(String[] args) { DisplayCard frame = new DisplayCard(); frame.setTitle("TestImageIcon"); frame.setSize(500, 125); frame.setLocationRelativeTo(null); // Center the frame frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
here is the error message
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at DisplayCard.main(DisplayCard.java:32)
Appreciate the help guys.