title: Linking Images in a Java Program
body: <p>Quick question I have a java file called Board.java which creates and places chess pieces on it, but I have a problem currently it only makes the chess board itself but does not assign the pieces </p>
  
  <p>I assume I am not linking the png's right </p>
  
  <p>Here is a screenshot of the my setup I am using Netbeans to build the game I have screenshot it so you can see where the images are stored and how I have so far written the program</p>
  
  <p>Also before you ask i am not getting errors when I run the program it just pops up an empty chess board with not pieces </p>
  
  <p><img src="https://i.stack.imgur.com/0xwEZ.png" alt="enter image description here"></p>
  
  <p>Also here is the Java file </p>
  
  <p>Board.java</p>
  
  <pre><code>package chessgame;
  
  import java.awt.*;
  import java.awt.event.*;
  import java.util.*;
  import javax.swing.*;
  import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE;
  
  public class Board extends JFrame  {
  
      JLayeredPane layeredPane;
      JPanel chessBoard;
      JLabel chessPiece;
      int xAdjustment;
      int yAdjustment;
      int startX;
      int startY;
      int initialX;
      int initialY;
      JPanel panels;
      JLabel pieces;
  
      public  Board(){
          Dimension boardSize = new Dimension(700, 700);
  
          //  This is a Layered Pane for this application
          layeredPane = new JLayeredPane();
          getContentPane().add(layeredPane);
          layeredPane.setPreferredSize(boardSize);
  
          //Add a chess board to the Layered Pane
          chessBoard = new JPanel();
          layeredPane.add(chessBoard, JLayeredPane.DEFAULT_LAYER);
          chessBoard.setLayout( new GridLayout(8, 8) );
          chessBoard.setPreferredSize( boardSize );
          chessBoard.setBounds(0, 0, boardSize.width, boardSize.height);
  
          for (int i = 0; i &lt; 64; i++) {
              JPanel square = new JPanel( new BorderLayout() );
              chessBoard.add( square );
  
              int row = (i / 8) % 2;
              if (row == 0)
                  square.setBackground( i % 2 == 0 ? Color.white : Color.gray );
              else
                  square.setBackground( i % 2 == 0 ? Color.gray : Color.white );
          }
          // Setting up the Initial Chess board.
          for(int i=8;i &lt; 16; i++){
              pieces = new JLabel( new ImageIcon("WhitePawn.png") );
              panels = (JPanel)chessBoard.getComponent(i);
              panels.add(pieces);
          }
          pieces = new JLabel( new ImageIcon("WhiteRook.png") );
          panels = (JPanel)chessBoard.getComponent(0);
          panels.add(pieces);
          pieces = new JLabel( new ImageIcon("WhiteKnight.png") );
          panels = (JPanel)chessBoard.getComponent(1);
          panels.add(pieces);
          pieces = new JLabel( new ImageIcon("WhiteKnight.png") );
          panels = (JPanel)chessBoard.getComponent(6);
          panels.add(pieces);
          pieces = new JLabel( new ImageIcon("WhiteBishup.png") );
          panels = (JPanel)chessBoard.getComponent(2);
          panels.add(pieces);
          pieces = new JLabel( new ImageIcon("WhiteBishup.png") );
          panels = (JPanel)chessBoard.getComponent(5);
          panels.add(pieces);
          pieces = new JLabel( new ImageIcon("WhiteKing.png") );
          panels = (JPanel)chessBoard.getComponent(3);
          panels.add(pieces);
          pieces = new JLabel( new ImageIcon("WhiteQueen.png") );
          panels = (JPanel)chessBoard.getComponent(4);
          panels.add(pieces);
          pieces = new JLabel( new ImageIcon("WhiteRook.png") );
          panels = (JPanel)chessBoard.getComponent(7);
          panels.add(pieces);
          for(int i=48;i &lt; 56; i++){
              pieces = new JLabel( new ImageIcon("BlackPawn.png") );
              panels = (JPanel)chessBoard.getComponent(i);
              panels.add(pieces);
          }
          pieces = new JLabel( new ImageIcon("PieceImages/BlackRook.png") );
          panels = (JPanel)chessBoard.getComponent(56);
          panels.add(pieces);
          pieces = new JLabel( new ImageIcon("BlackKnight.png") );
          panels = (JPanel)chessBoard.getComponent(57);
          panels.add(pieces);
          pieces = new JLabel( new ImageIcon("BlackKnight.png") );
          panels = (JPanel)chessBoard.getComponent(62);
          panels.add(pieces);
          pieces = new JLabel( new ImageIcon("BlackBishup.png") );
          panels = (JPanel)chessBoard.getComponent(58);
          panels.add(pieces);
          pieces = new JLabel( new ImageIcon("BlackBishup.png") );
          panels = (JPanel)chessBoard.getComponent(61);
          panels.add(pieces);
          pieces = new JLabel( new ImageIcon("BlackKing.png") );
          panels = (JPanel)chessBoard.getComponent(59);
          panels.add(pieces);
          pieces = new JLabel( new ImageIcon("BlackQueen.png") );
          panels = (JPanel)chessBoard.getComponent(60);
          panels.add(pieces);
          pieces = new JLabel( new ImageIcon("BlackRook.png") );
          panels = (JPanel)chessBoard.getComponent(63);
          panels.add(pieces);
      }
  }
  </code></pre>
  
  <p>Thanks for reading any help is welcomed </p>