title: Java blackjack swing gui ImageIcon
body: <p>I've just started Java a week ago and have finished my first blackjack program.
  I want to enhance it by using Java swing (ImageIcon) so that each time I draw a card, let's say an ace it actually displays the ace as an image on the screen or my current hand.
  I have written this program which displays the cards I want:</p>
  
  <pre><code>import java.awt.FlowLayout;
  import javax.swing.*;
  
  public class TenCards extends JFrame {
  
      public TenCards() {
  
          ImageIcon[] images = new ImageIcon[10];
          // Saved the card images as 1,2,3...10.gif in my package
          // looped them into the images list
          for (int i = 1; i &lt; images.length; i++) {
              images[i] = new ImageIcon((getClass().getResource(i + ".gif")));
  
              // testing by displaying 7,8 and 9 cards
          }
          setLayout(new FlowLayout(1, 1, 1));
          add(new JLabel(images[7]));
          add(new JLabel(images[8]));
          add(new JLabel(images[9]));
  
      }
  
      public static void main(String[] args) {
          // TODO Auto-generated method stub
  
          JFrame frame = new TenCards();
          frame.setTitle("Testing!");
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setVisible(true);
      }
  }
  </code></pre>
  
  <blockquote>
    <p><strong>Now my question is, given I have my blackjack class or program in another file, how do I combine both classes so that I can use all this image stuff in my blackjack program?</strong> I tried copy pasting my TenCards program into the Blackjack one to no avail :( If anyone could lend me a hand or point me towards the next step I would really appreciate it.</p>
  </blockquote>
  
  <hr>
  
  <p><strong>EDIT</strong> I have now included my blackjack program and deleted the other because stackoverflow wouldn't accept both combined because there was too much code.</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Scanner;
  
  import javax.swing.JLabel;
  
  public class myblackjack {
      public static void main(String[] args) {
          // TODO Auto-generated method stub
      Scanner sc = new Scanner(System.in);
  
      ArrayList&lt;Integer&gt; player = new ArrayList&lt;Integer&gt;();
      ArrayList&lt;Integer&gt; dealer = new ArrayList&lt;Integer&gt;();
      ArrayList&lt;Integer&gt; cards = new ArrayList&lt;Integer&gt;();
  
      // Ace is 1 as per Amos' instructions
      for ( int i =1; i &lt;= 10; i++){
          cards.add(i);}
      // The 3 face cards representing 10
      for (int z = 0; z &lt;= 2; z++){
          cards.add(10);}
  
  
      player.add(cards.get((int) (Math.random()*12)));
      player.add(cards.get((int) (Math.random()*12)));
      dealer.add(cards.get((int) (Math.random()*12)));
      dealer.add(cards.get((int) (Math.random()*12)));
      System.out.println("Your cards: "+player);
      boolean moreplayer = true, morecomputer = true;
      System.out.println("Hit 0 to stop, 1 for another card");
      int s1 = sc.nextInt();
      while (moreplayer || morecomputer){
          int dealersum = 0, playersum = 0 ;
  
          for (int p = 0; p&lt;dealer.size(); p++){
              dealersum = dealersum + dealer.get(p);
          } if (dealersum&lt;15){
              morecomputer = true;
              dealer.add(cards.get((int) (Math.random()*12)));
                  dealersum = dealersum + dealer.get(2);
              }else{ morecomputer = false;
  
          }if (s1 == 1){
  
              moreplayer = true;
              player.add(cards.get((int) (Math.random()*12)));
              for (int b = 0; b&lt;player.size(); b++){
                  playersum = playersum + player.get(b);
  
  
              } System.out.println("Your cards: "+player);
              System.out.println("Hit 0 to stop, 1 for another card");
              s1 = sc.nextInt();
              }else if (s1 == 0){ 
                  moreplayer = false;
                  for (int b = 0; b&lt;player.size(); b++){
                      playersum = playersum + player.get(b);
  
  
                  }}if (playersum&gt;21 &amp;&amp; (moreplayer || morecomputer)){
                  moreplayer = false; morecomputer = false;
                  System.out.println(dealer + "dealer");
                  System.out.println("You've gone bust player, computer wins!");
  
              }if (dealersum&gt;21 &amp;&amp; (moreplayer || morecomputer)){
                  moreplayer = false; morecomputer = false;
                  System.out.println(dealer + "dealer");
                  System.out.println(player + "player");
                  System.out.println("Computer has gone bust, player wins!");
  
              }if (playersum&gt;dealersum &amp;&amp; (!morecomputer &amp;&amp; !moreplayer) &amp;&amp; (dealersum&lt;=21 &amp;&amp; playersum &lt;=21)){
                  System.out.println("Player wins!");
                  System.out.println(dealer + "dealer");
  
  
                  moreplayer = false; morecomputer = false;
              }if (dealersum&gt;playersum &amp;&amp; (!morecomputer &amp;&amp; !moreplayer) &amp;&amp; (dealersum&lt;=21   &amp;&amp; playersum &lt;=21)){
                  System.out.println("Dealer wins");
                  System.out.println(dealer + "dealer");
  
                  moreplayer = false; morecomputer = false;
              } if ((dealersum == playersum) &amp;&amp; (!morecomputer &amp;&amp; !moreplayer) &amp;&amp; (dealersum&lt;=21 &amp;&amp; playersum &lt;=21)){
                  System.out.println("TIE!");
                  System.out.println(dealer + "dealer");
  
                  moreplayer = false; morecomputer = false;
  
  
          }
              sc.close()  ;
  
      }
  
      }
      }/** I didn't consider suits, ace is value 1 and all 3 face cards are worth 10 points */
  </code></pre>
  
  <p>regards,
  M</p>