Monday, October 18, 2010

JAVA SOURCE CODE FOR CHESS BOARD

import java.awt.*;
import javax.swing.*;

public class ElliotChess extends JFrame {

    private JPanel mainPanel;
    private DrawingPanel drawPanel;
    static ElliotChess myChessBoard;
    private int x = 100, y = 60;

    public ElliotChess() {
   
        super("CHESS BOARD WITH CHESS PIECES");
   
        mainPanel = new JPanel();
        mainPanel.setLayout(null);
        mainPanel.setBackground(Color.RED);

        drawPanel= new DrawingPanel();
        drawPanel.setBounds(mainPanel.getWidth() / 2, mainPanel.getHeight() / 2, 1000, 1000);
        drawPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 5));
        mainPanel.add(drawPanel, BorderLayout.CENTER);
        setContentPane(mainPanel);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(1020,720);
        setLocationRelativeTo(null);
        setVisible(true);

      

    }

    public static void main(String[] args) {
         myChessBoard = new  ElliotChess();
           }


    class DrawingPanel extends JPanel {
      private int x = 100, y = 60;   

       protected void paintComponent(Graphics g) {
          super.paintComponent(g);
          Graphics2D g2d = (Graphics2D) g;
          drawingMethod(g2d);
       }

    private void drawingMethod(Graphics2D g2d) {
       
       for (int i = 0; i <= 8; ++i) {
            g2d.drawLine(x, (y * i) + 60, x + 800, (y * i) + 60);
            
            }
         
        for (int j = 0; j <= 8; ++j) {
                g2d.drawLine((x * j) + 100, y, (x * j) + 100, y + 480);
            }
      
        g2d.setColor(Color.BLACK);
        g2d.fillRect(200, 60, 100, 60);       
      
        ImageIcon myImage3 = new ImageIcon("C:\\Users\\Ganizani\\Documents\\chesspieces\\h.JPG");
        Image picImage3 = myImage3.getImage();
        g2d.drawImage(picImage3,130,65, this);
       
        ImageIcon myImage = new ImageIcon("C:\\Users\\Ganizani\\Documents\\chesspieces\\i.jpg");
        Image picImage = myImage.getImage();
        g2d.drawImage(picImage, 230,65, this);
       
        ImageIcon myImage6 = new ImageIcon("C:\\Users\\Ganizani\\Documents\\chesspieces\\g.jpg");
        Image picImage6 = myImage6.getImage();
        g2d.drawImage(picImage6, 330,65, this);
       
        g2d.fillRect(400, 60, 100, 60);
        ImageIcon myImage8 = new ImageIcon("C:\\Users\\Ganizani\\Documents\\chesspieces\\l.jpg");
        Image picImage8 = myImage8.getImage();
        g2d.drawImage(picImage8, 430,61, this);     
             
       
        ImageIcon myImage9 = new ImageIcon("C:\\Users\\Ganizani\\Documents\\chesspieces\\k.jpg");
        Image picImage9 = myImage9.getImage();
       
       g2d.fillRect(100, 120, 100, 60);
        g2d.fillRect(300, 120, 100, 60);
        g2d.fillRect(500, 120, 100, 60);
        g2d.fillRect(700, 120, 100, 60);

        g2d.drawImage(picImage9, 130,125, this);       
        g2d.drawImage(picImage9, 230,125, this);       
        g2d.drawImage(picImage9, 330,125, this);       
        g2d.drawImage(picImage9, 430,125, this);       
        g2d.drawImage(picImage9, 530,125, this);      
        g2d.drawImage(picImage9, 630,125, this);       
        g2d.drawImage(picImage9, 730,125, this);
        g2d.drawImage(picImage9, 830,125, this);        

        g2d.fillRect(200, 180, 100, 60);
        g2d.fillRect(400, 180, 100, 60);
        g2d.fillRect(600, 180, 100, 60);
        g2d.fillRect(800, 180, 100, 60);       
      
        g2d.fillRect(100, 240, 100, 60);
        g2d.fillRect(300, 240, 100, 60);
        g2d.fillRect(500, 240, 100, 60);
        g2d.fillRect(700, 240, 100, 60);
         
        g2d.fillRect(200, 300, 100, 60);
        g2d.fillRect(400, 300, 100, 60);
        g2d.fillRect(600, 300, 100, 60);
       g2d.fillRect(800, 300, 100, 60);
         
        g2d.fillRect(100, 360, 100, 60);
        g2d.fillRect(300, 360, 100, 60);
        g2d.fillRect(500, 360, 100, 60);
        g2d.fillRect(700, 360, 100, 60);

        g2d.fillRect(800, 60, 100, 60);
        
        ImageIcon myImage4 = new ImageIcon("C:\\Users\\Ganizani\\Documents\\chesspieces\\h.jpg");
        Image picImage4 = myImage4.getImage();
        g2d.drawImage(picImage4, 830,65, this);
       
        ImageIcon myImage2 = new ImageIcon("C:\\Users\\Ganizani\\Documents\\chesspieces\\i.jpg");
        Image picImage2 = myImage2.getImage();
        g2d.drawImage(picImage2,730,65, this);
       
        g2d.fillRect(600, 60, 100, 60);
        ImageIcon myImage5 = new ImageIcon("C:\\Users\\Ganizani\\Documents\\chesspieces\\g.jpg");
        Image picImage5 = myImage5.getImage();
        g2d.drawImage(picImage5, 630,65, this);
       
        ImageIcon myImage7 = new ImageIcon("C:\\Users\\Ganizani\\Documents\\chesspieces\\j.jpg");
        Image picImage7 = myImage7.getImage();
        g2d.drawImage(picImage7, 530,61, this);


              
        ImageIcon myImage17 = new ImageIcon("C:\\Users\\Ganizani\\Documents\\chesspieces\\e.jpg");
        Image picImage17 = myImage17.getImage();
        g2d.drawImage(picImage17,130,428, this);
       
        g2d.fillRect(200, 420, 100, 60);
        g2d.fillRect(400, 420, 100, 60);
        g2d.fillRect(600, 420, 100, 60);
        g2d.fillRect(800, 420, 100, 60);
        g2d.fillRect(100, 480, 100, 60);
        
        g2d.drawImage(picImage17,230,428, this);
        g2d.drawImage(picImage17,330,428, this);
        g2d.drawImage(picImage17,430,428, this);     
        g2d.drawImage(picImage17,530,428, this);
        g2d.drawImage(picImage17,630,428, this);
        g2d.drawImage(picImage17,730,428, this);
        g2d.drawImage(picImage17,830,428, this);
     
        ImageIcon myImage50 = new ImageIcon("C:\\Users\\Ganizani\\Documents\\chesspieces\\b.jpg");
        Image picImage50 = myImage50.getImage();
        g2d.drawImage(picImage50,130,486, this);

      
        ImageIcon myImage28 = new ImageIcon("C:\\Users\\Ganizani\\Documents\\chesspieces\\c.jpg");
        Image picImage28 = myImage28.getImage();
        g2d.drawImage(picImage28,230,486, this);
       
        g2d.fillRect(300, 480, 100, 60);
        ImageIcon myImage29 = new ImageIcon("C:\\Users\\Ganizani\\Documents\\chesspieces\\a.jpg");
        Image picImage29 = myImage29.getImage();
        g2d.drawImage(picImage29,330,486, this);
       
        ImageIcon myImage25 = new ImageIcon("C:\\Users\\Ganizani\\Documents\\chesspieces\\b.jpg");
        Image picImage25 = myImage25.getImage();
        g2d.drawImage(picImage25,830,486, this);
      
        g2d.fillRect(700, 480, 100, 60);
        ImageIcon myImage27 = new ImageIcon("C:\\Users\\Ganizani\\Documents\\chesspieces\\c.jpg");
        Image picImage27 = myImage27.getImage();
        g2d.drawImage(picImage27,730,486, this);
       
        ImageIcon myImage30 = new ImageIcon("C:\\Users\\Ganizani\\Documents\\chesspieces\\a.jpg");
        Image picImage30 = myImage30.getImage();
        g2d.drawImage(picImage30,630,486, this);
       
        g2d.fillRect(500, 480, 100, 60);
        ImageIcon myImage31 = new ImageIcon("C:\\Users\\Ganizani\\Documents\\chesspieces\\d.jpg");
        Image picImage31 = myImage31.getImage();
        g2d.drawImage(picImage31,530,480, this);
       
        ImageIcon myImage32 = new ImageIcon("C:\\Users\\Ganizani\\Documents\\chesspieces\\f.jpg");
        Image picImage32 = myImage32.getImage();
        g2d.drawImage(picImage32,430,480, this);
         
         }
      }
   }

No comments:

Post a Comment