Friday, October 22, 2010

CHESS INTERFACE BY JOHN CHAMDIMBA


INSTRUCTIONS:

Ø  Load each and every part of the JGrasp java files into the compiler.
Ø  Run the program and you will see the interface of chess


MAIN OBJECTIVES
The primary aim of the interface was to see how to draw graphics using 2D Graphics and also how to import pictures into your drawings.
NB: the pieces on the chessboard do not move but in my next chess publish I will publish the whole game where you can play either by the computer or with your friend.

Process
After running the program this is the chess interface which will be displayed on your screen.
.

HERE IS THE SOURCE CODE OF THE CHESS INTERFACE PROGRAM WRITTEN IN JAVA COMPUTER PROGRAMMING LANGUAGE


// PROGRAMMER:JOHN CHAMDIMBA
// BSc.MATHEMATICAL SCIENCES EDUCATION-STATISTICS AND COMPUTING
// PROGRAM:CHESS (C)2010

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


 
public class chessJohnChamdimba {

 
public static void main(String[] args)
     {        

        MakeFrame frame =
new MakeFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.show();
     }     
   
}

 
class MakeFrame extends JFrame
 {
   
        
public MakeFrame()
     {           
       setSize(700, 742);     
       setLocation(500,60);
       setResizable(
true);     
       setTitle(
"CHESS-------JOHN CHAMDIMBA--------");      

       MakePanel panel =
new MakePanel();
       panel.setLayout(
new BorderLayout());

  
       JPanel panelNijo=
new JPanel();
       panelNijo.setBackground(Color.green); 
      
       JButton button1=
new JButton("New Game");
       JButton button2=
new JButton("Help");
       JButton button3=
new JButton("Previous Game");
       JButton button4=
new JButton("Save Game");
  
       panelNijo.add(button1);
       panelNijo.add(button3);
       panelNijo.add(button4);
       panelNijo.add(button2);
      
       Container contentPane = getContentPane();
       contentPane.setLayout(
new BorderLayout());

       contentPane.add(panel,BorderLayout.CENTER);
       contentPane.add(panelNijo,BorderLayout.NORTH);

     }
 
 }

     
 
class MakePanel extends JPanel
 {
  
    ImageIcon picIcon =
new ImageIcon("D:\\chess1\\bb.jpg");
    Image picImage = picIcon.getImage();
   
    ImageIcon picIcon2 =
new ImageIcon("D:\\chess1\\bc.jpg");
    Image picImage2 = picIcon2.getImage();
   
    ImageIcon picIcon3 =
new ImageIcon("D:\\chess1\\bk.jpg");
    Image picImage3 = picIcon3.getImage();
   
    ImageIcon picIcon4 =
new ImageIcon("D:\\chess1\\bp.jpg");
    Image picImage4 = picIcon4.getImage();

    ImageIcon picIcon5 =
new ImageIcon("D:\\chess1\\bh.jpg");
    Image picImage5 = picIcon5.getImage();
 
    ImageIcon picIcon6 =
new ImageIcon("D:\\chess1\\bq.jpg");
    Image picImage6 = picIcon6.getImage();
   
    ImageIcon picIcon7 =
new ImageIcon("D:\\chess1\\wb.jpg");
    Image picImage7 = picIcon7.getImage();
   
    ImageIcon picIcon12 =
new ImageIcon("D:\\chess1\\wcc.jpg");
    Image picImage12 = picIcon12.getImage();
   
    ImageIcon picIcon8 =
new ImageIcon("D:\\chess1\\wk.jpg");
    Image picImage8 = picIcon8.getImage();
   
    ImageIcon picIcon9 =
new ImageIcon("D:\\chess1\\wp.jpg");
    Image picImage9 = picIcon9.getImage();

    ImageIcon picIcon10 =
new ImageIcon("D:\\chess1\\wh.jpg");
    Image picImage10 = picIcon10.getImage();
 
    ImageIcon picIcon11 =
new ImageIcon("D:\\chess1\\wq.jpg");
    Image picImage11 = picIcon11.getImage();



   
public void paintComponent(Graphics g)
    {
       MakeFrame frame =
new MakeFrame();
      
int start1=0;
      
int start2=0;
      
int x=start1;
      
int y=start2;
      
int numberOfbox=8;
      
int sizeOfbox=85;
      
boolean paint=false;
      
      
super.paintComponent(g);
       Graphics2D g2 = (Graphics2D)g;      
      
for(int a=0;a<numberOfbox;a++)
       {
      
if(a%2==0)
       {paint=
false;}
      
else if(a%2==1)
        {paint=
true;} 
       x=start1;
      
for(int b=0;b<numberOfbox;b++)
        {               
       
if(paint==true)
        {
        g2.setPaint(Color.white);
        g2.fill(
new Rectangle2D.Double(x,y,sizeOfbox,sizeOfbox));
     
     
//line number one black
        g2.drawImage(picImage2, 15, 15, this);
        g2.drawImage(picImage, 190,15,
this);
        g2.drawImage(picImage6, 350,15,
this);
        g2.drawImage(picImage5, 530,15,
this);
       
          g2.drawImage(picImage5, 100, 15,
this);
          g2.drawImage(picImage3, 260,15,
this);
          g2.drawImage(picImage2, 600,15,
this);
          g2.drawImage(picImage, 440,15,
this);
       

     
//line number two black
        g2.drawImage(picImage4, 100,100, this);
        g2.drawImage(picImage4, 280,100,
this);
        g2.drawImage(picImage4, 450,100,
this);
        g2.drawImage(picImage4, 615,100,
this);
       
        g2.drawImage(picImage4, 10,100,
this);
        g2.drawImage(picImage4, 190,100,
this);
        g2.drawImage(picImage4, 350,100,
this);
        g2.drawImage(picImage4, 530,100,
this);
      

      
        paint=
false;
        }
       
else
        {
        g2.setPaint(Color.red);
        g2.fill(
new Rectangle2D.Double(x,y,sizeOfbox,sizeOfbox));
      
      
//line number one back white
        g2.drawImage(picImage9, 15, 530, this);
        g2.drawImage(picImage9, 187,530,
this);
        g2.drawImage(picImage9, 527,530,
this);
        g2.drawImage(picImage9, 350,530,
this);  
        g2.drawImage(picImage9, 100, 530,
this)
        g2.drawImage(picImage9, 267,530,
this);
        g2.drawImage(picImage9, 437,530,
this);
        g2.drawImage(picImage9, 610,530,
this);
       
      
//line number far back white
        g2.drawImage(picImage12, 605,610, this);
         g2.drawImage(picImage10, 95,610,
this);
         g2.drawImage(picImage7, 445,610,
this);
         g2.drawImage(picImage8, 275,610,
this);
       
         g2.drawImage(picImage12, 25,610,
this);
         g2.drawImage(picImage7,  185,610,
this);
         g2.drawImage(picImage11, 345,610,
this);
         g2.drawImage(picImage10, 540,610,
this);
    

        paint=
true;
       }
        x+=sizeOfbox;
       }                   
        y+=sizeOfbox;
       }
    }
}
//end of program

No comments:

Post a Comment