Tuesday, October 19, 2010

chess board designed by Ezra Machira

The diagram above shows the chess board without pieces





below is the source code for chess board 
import java.awt.*;
import javax.swing.*;

public class Chess_ezra extends JFrame {

    private JPanel myPanel;
    private DrawingPanel drawPanel;
     static Chess_ezra myChessBoard;
     private int x = 100, y = 60;

    public Chess_ezra() {
   
           super("Chess ");
   
        myPanel = new JPanel();
        myPanel.setLayout(null);
        myPanel.setBackground(Color.ORANGE);

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

      

    }

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


     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);
           g2d.setFont(new Font("algerian", Font.PLAIN, 20));

         
          g2d.drawString("CHESS BOARD ",380, 50);
           g2d.setFont(new Font("constantia", Font.PLAIN,30));
          g2d.drawString("designed by Ezra F. Machira!",580, 690);
          ImageIcon myImage3 = new ImageIcon("d:\\machira\\chess2.png");
          Image picImage3 = myImage3.getImage();
          g2d.drawImage(picImage3,130,65, this);
          ImageIcon myImage = new ImageIcon("d:\\machira\\chess1.png");
          Image picImage = myImage.getImage();
          g2d.drawImage(picImage, 230,65, this);
         


          ImageIcon myImage6 = new ImageIcon("d:\\machira\\chess3.png");
          Image picImage6 = myImage6.getImage();
          g2d.drawImage(picImage6, 330,65, this);
         
         g2d.fillRect(400, 60, 100, 60);
          ImageIcon myImage8 = new ImageIcon("d:\\machira\\chess5.png");
          Image picImage8 = myImage8.getImage();
          g2d.drawImage(picImage8, 430,61, this);         
                  
         
          ImageIcon myImage9 = new ImageIcon("d:\\machira\\chess2.png");
          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("d:\\machira\\chess2.png");
          Image picImage4 = myImage4.getImage();
          g2d.drawImage(picImage4, 830,65, this);
         
          ImageIcon myImage2 = new ImageIcon("d:\\machira\\chess1.png");
          Image picImage2 = myImage2.getImage();
          g2d.drawImage(picImage2,730,65, this);
         
          g2d.fillRect(600, 60, 100, 60);
          ImageIcon myImage5 = new ImageIcon("d:\\machira\\chess3.png");
          Image picImage5 = myImage5.getImage();
          g2d.drawImage(picImage5, 630,65, this);
         
          ImageIcon myImage7 = new ImageIcon("d:\\machira\\chess4.png");
          Image picImage7 = myImage7.getImage();
          g2d.drawImage(picImage7, 530,61, this);


                   
          ImageIcon myImage17 = new ImageIcon("d:\\machira\\chess6.png");
          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);
          g2d.drawImage(picImage17,130,486, this);
         
       
          ImageIcon myImage28 = new ImageIcon("d:\\machira\\chess7.png");
          Image picImage28 = myImage28.getImage();
          g2d.drawImage(picImage28,230,486, this);
         
          g2d.fillRect(300, 480, 100, 60);
          ImageIcon myImage29 = new ImageIcon("d:\\machira\\chess8.png");
          Image picImage29 = myImage29.getImage();
          g2d.drawImage(picImage29,330,486, this);
         
          ImageIcon myImage25 = new ImageIcon("d:\\machira\\chess6.png");
          Image picImage25 = myImage25.getImage();
          g2d.drawImage(picImage25,830,486, this);
       
          g2d.fillRect(700, 480, 100, 60);
          ImageIcon myImage27 = new ImageIcon("d:\\machira\\chess7.png");
          Image picImage27 = myImage27.getImage();
          g2d.drawImage(picImage27,730,486, this);
         
          ImageIcon myImage30 = new ImageIcon("d:\\machira\\chess8.png");
          Image picImage30 = myImage30.getImage();
          g2d.drawImage(picImage30,630,486, this);
         
          g2d.fillRect(500, 480, 100, 60);
          ImageIcon myImage31 = new ImageIcon("d:\\machira\\chess9.png");
          Image picImage31 = myImage31.getImage();
          g2d.drawImage(picImage31,530,480, this);
         
          ImageIcon myImage32 = new ImageIcon("d:\\machira\\chess10.png");
          Image picImage32 = myImage32.getImage();
          g2d.drawImage(picImage32,430,480, this);
             
             }
         }
    }

No comments:

Post a Comment