Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy doesn't my code display an image in a JPanel?
    primarykey
    data
    text
    <p>I have a problem with my program.</p> <pre><code>package game; import java.util.Random; import javax.swing.ImageIcon; public class deck { private Card deckOfCards[]; private final int number_cards = 52; private Random various; private int currentCard; private int actualCard; public ImageIcon CardImage; public deck() { int value[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11 }; ImageIcon[] image = { new ImageIcon("/root/Desktop/as.jpg"), new ImageIcon("/root/Desktop/as.jpg"), new ImageIcon("/root/Desktop/as.jpg"), new ImageIcon("/root/Desktop/as.jpg"), new ImageIcon("/root/Desktop/as.jpg"), new ImageIcon("/root/Desktop/as.jpg"), new ImageIcon("/root/Desktop/as.jpg"), new ImageIcon("/root/Desktop/as.jpg"), new ImageIcon("/root/Desktop/as.jpg"), new ImageIcon("/root/Desktop/as.jpg"), new ImageIcon("/root/Desktop/as.jpg"), new ImageIcon("/root/Desktop/as.jpg"), new ImageIcon("/root/Desktop/as.jpg"), }; currentCard = 0; deckOfCards = new Card[number_cards]; various = new Random(); for (int count = 0; count &lt; deckOfCards.length; count++) { deckOfCards[count] = new Card(Rank.values()[count % 13].toString(),Suit.values()[count / 13].toString(), value[count % 13], image[count % 13]); } } public void shuffle() { currentCard = 0; for (int first = 0; first &lt; deckOfCards.length; first++) { int second = various.nextInt(number_cards); Card temp = deckOfCards[first]; deckOfCards[first] = deckOfCards[second]; deckOfCards[second] = temp; } } public Card giveCard() { if (currentCard &lt; deckOfCards.length) return deckOfCards[currentCard++]; else System.out.println("No more Cards."); return null; } public int totalValue() { int cardValue = (deckOfCards[actualCard].toInt()); return cardValue; } public ImageIcon getImage() { return CardImage; } } package game; import java.awt.Image; import javax.swing.ImageIcon; public class Card { private final String faceCard; private final String suit; private final int number; public ImageIcon image; Card(String faceCard, String suit, int number_, ImageIcon image) { this.faceCard = faceCard; this.suit = suit; this.number = number_; this.image = image; } public String toString() { return faceCard + " of " + suit + "\n" + "Value of card: " + number; } public int toInt() { return number; } public void setImage(ImageIcon image) { this.image = image; } public ImageIcon getImage() { return image; } } //swing part ImageIcon pic = new ImageIcon(myDeckOfCards.getImage()); panel2.add(lab1); panel2.add(new JLabel(pic)); panel2.add(card1); panel2.add(pn1); panel2.add(btn1); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload