Results 1 to 3 of 3

Thread: ChessGame

  1. #1
    Dastagir is offline Member
    Join Date
    Dec 2011
    Posts
    5
    Rep Power
    0

    Default ChessGame

    where i hav to insert/store images for


    ImageArray_TOP[0] = "pieces/top/1brook.gif";
    in da folloing code???


    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;

    public class ChessGame extends JFrame implements MouseListener, MouseMotionListener {
    JLayeredPane layeredPane;
    JPanel chessBoard;
    JLabel chessPiece;
    int xAdjustment;
    int yAdjustment;
    int posFrom;
    Pieces boardPieces = new Pieces();





    public ChessGame(){


    Dimension boardSize = new Dimension(600, 600);

    // Use a Layered Pane for this this application

    layeredPane = new JLayeredPane();
    getContentPane().add(layeredPane);
    layeredPane.setPreferredSize(boardSize);
    layeredPane.addMouseListener(this);
    layeredPane.addMouseMotionListener(this);




    //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);

    Color Green = new Color(119,170,119);
    Color Cream = new Color(250,235,215);

    for (int i = 0; i < 64; i++) {
    JPanel square = new JPanel( new BorderLayout() );
    chessBoard.add( square );

    int row = (i / 8) % 2;
    if (row == 0)
    square.setBackground( i % 2 == 0 ? Green : Cream );
    else
    square.setBackground( i % 2 == 0 ? Cream : Green );
    }


    /** Pieces for the board */

    // Image String array - TOP ROWS

    String[] ImageArray_TOP = new String[16];

    ImageArray_TOP[0] = "pieces/top/1brook.gif";
    ImageArray_TOP[1] = "pieces/top/1bknight.gif";
    ImageArray_TOP[2] = "pieces/top/1bbishop.gif";
    ImageArray_TOP[3] = "pieces/top/1bqueen.gif";
    ImageArray_TOP[4] = "pieces/top/1bking.gif";
    ImageArray_TOP[5] = "pieces/top/1bbishop.gif";
    ImageArray_TOP[6] = "pieces/top/1bknight.gif";
    ImageArray_TOP[7] = "pieces/top/1brook.gif";

    ImageArray_TOP[8] = "pieces/top/1bpawn.gif";
    ImageArray_TOP[9] = "pieces/top/1bpawn.gif";
    ImageArray_TOP[10] = "pieces/top/1bpawn.gif";
    ImageArray_TOP[11] = "pieces/top/1bpawn.gif";
    ImageArray_TOP[12] = "pieces/top/1bpawn.gif";
    ImageArray_TOP[13] = "pieces/top/1bpawn.gif";
    ImageArray_TOP[14] = "pieces/top/1bpawn.gif";
    ImageArray_TOP[15] = "pieces/top/1bpawn.gif";

    // Image String Array - BOTTOM ROWS

    String[] ImageArray_BOTTOM = new String[16];

    ImageArray_BOTTOM[0] = "pieces/bottom/rpawn.gif";
    ImageArray_BOTTOM[1] = "pieces/bottom/rpawn.gif";
    ImageArray_BOTTOM[2] = "pieces/bottom/rpawn.gif";
    ImageArray_BOTTOM[3] = "pieces/bottom/rpawn.gif";
    ImageArray_BOTTOM[4] = "pieces/bottom/rpawn.gif";
    ImageArray_BOTTOM[5] = "pieces/bottom/rpawn.gif";
    ImageArray_BOTTOM[6] = "pieces/bottom/rpawn.gif";
    ImageArray_BOTTOM[7] = "pieces/bottom/rpawn.gif";

    ImageArray_BOTTOM[8] = "pieces/bottom/rrook.gif";
    ImageArray_BOTTOM[9] = "pieces/bottom/rknight.gif";
    ImageArray_BOTTOM[10] = "pieces/bottom/rbishop.gif";
    ImageArray_BOTTOM[11] = "pieces/bottom/rqueen.gif";
    ImageArray_BOTTOM[12] = "pieces/bottom/rking.gif";
    ImageArray_BOTTOM[13] = "pieces/bottom/rbishop.gif";
    ImageArray_BOTTOM[14] = "pieces/bottom/rknight.gif";
    ImageArray_BOTTOM[15] = "pieces/bottom/rrook.gif";

    // Add pieces to the board (TOP)

    for( int i = 0; i < 16; i++) {

    JLabel piece = new JLabel( new ImageIcon(ImageArray_TOP[i]) );
    JPanel panel = (JPanel)chessBoard.getComponent(i);
    panel.add(piece);

    }

    // Add pieces to the board (BOTTOM)
    int inc = 48;
    for( int j = 0; j < 16; j++, inc++) {

    JLabel piece = new JLabel( new ImageIcon(ImageArray_BOTTOM[j]) );
    JPanel panel = (JPanel)chessBoard.getComponent(inc);
    panel.add(piece);

    }

    }

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: ChessGame

    where i hav to insert/store images for


    ImageArray_TOP[0] = "pieces/top/1brook.gif";
    in da folloing code???
    First word of advice - don't write lazily. 'Da' and 'folloing' are not words - if you spend next to no time composing your post expect that in return. Second word of advice, use the code tags. Last piece of advice, ask a question.

  3. #3
    Dastagir is offline Member
    Join Date
    Dec 2011
    Posts
    5
    Rep Power
    0

    Default Re: ChessGame

    thanx...i am facing problem with adding the images of pieces,can you please help me? i am not getting where to keep the images so that it will be added by the ImageIcon.

Similar Threads

  1. ChessGame
    By Dastagir in forum New To Java
    Replies: 2
    Last Post: 12-13-2011, 11:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •