INSTRUCTIONS:
Ø Load each and every part of the JGrasp java files into the compiler.
Ø Run the program and you will see the interface of checkers/draught
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 checkers 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 checkers interface which will be displayed on your screen.
HERE IS THE SOURCE CODE OF THE CHECKERS INTERFACE PROGRAM WRITTEN IN JAVA COMPUTER PROGRAMMING LANGUAGE
// PROGRAMMER:JOHN CHAMDIMBA
// BSc.MATHEMATICAL SCIENCES EDUCATION-STATISTICS AND COMPUTING
// PROGRAM:CHECKERS/DRAUGHT (C)2010
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
import java.awt.Color;
public class draftJohnChamdimba {
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("DRAFT-------JOHN CHAMDIMBA--------");
MakePanel panel = new MakePanel();
panel.setLayout(new BorderLayout());
JPanel panelNijo= new JPanel();
panelNijo.setBackground(Color.red);
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:\\fanta.png");
Image picImage = picIcon.getImage();
ImageIcon picIcon2 = new ImageIcon("D:\\spesho.png");
Image picImage2 = picIcon2.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
g2.drawImage(picImage, 15, 15, this);
g2.drawImage(picImage, 190,15, this);
g2.drawImage(picImage, 350,15, this);
g2.drawImage(picImage, 530,15, this);
//line number two
g2.drawImage(picImage, 100,100, this);
g2.drawImage(picImage, 280,100, this);
g2.drawImage(picImage, 450,100, this);
g2.drawImage(picImage, 615,100, this);
//line number three
g2.drawImage(picImage, 190,190, this);
g2.drawImage(picImage, 355,190, this);
g2.drawImage(picImage, 530,190, this);
g2.drawImage(picImage, 20,190, this);
paint=false;
}
else
{
g2.setPaint(Color.black);
g2.fill(new Rectangle2D.Double(x,y,sizeOfbox,sizeOfbox));
//line number one back
g2.drawImage(picImage2, 15, 530, this);
g2.drawImage(picImage2, 187,530, this);
g2.drawImage(picImage2, 527,530, this);
g2.drawImage(picImage2, 350,530, this);
//line number far back
g2.drawImage(picImage2, 605,610, this);
g2.drawImage(picImage2, 95,610, this);
g2.drawImage(picImage2, 445,610, this);
g2.drawImage(picImage2, 275,610, this);
//line number three far front
g2.drawImage(picImage2, 450,447, this);
g2.drawImage(picImage2, 270,447, this);
g2.drawImage(picImage2, 100,447, this);
g2.drawImage(picImage2, 610,447, this);
paint=true;
}
x+=sizeOfbox;
}
y+=sizeOfbox;
}
}
}//END OF PROGRAM
// BSc.MATHEMATICAL SCIENCES EDUCATION-STATISTICS AND COMPUTING
// PROGRAM:CHECKERS/DRAUGHT (C)2010
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
import java.awt.Color;
public class draftJohnChamdimba {
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("DRAFT-------JOHN CHAMDIMBA--------");
MakePanel panel = new MakePanel();
panel.setLayout(new BorderLayout());
JPanel panelNijo= new JPanel();
panelNijo.setBackground(Color.red);
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:\\fanta.png");
Image picImage = picIcon.getImage();
ImageIcon picIcon2 = new ImageIcon("D:\\spesho.png");
Image picImage2 = picIcon2.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
g2.drawImage(picImage, 15, 15, this);
g2.drawImage(picImage, 190,15, this);
g2.drawImage(picImage, 350,15, this);
g2.drawImage(picImage, 530,15, this);
//line number two
g2.drawImage(picImage, 100,100, this);
g2.drawImage(picImage, 280,100, this);
g2.drawImage(picImage, 450,100, this);
g2.drawImage(picImage, 615,100, this);
//line number three
g2.drawImage(picImage, 190,190, this);
g2.drawImage(picImage, 355,190, this);
g2.drawImage(picImage, 530,190, this);
g2.drawImage(picImage, 20,190, this);
paint=false;
}
else
{
g2.setPaint(Color.black);
g2.fill(new Rectangle2D.Double(x,y,sizeOfbox,sizeOfbox));
//line number one back
g2.drawImage(picImage2, 15, 530, this);
g2.drawImage(picImage2, 187,530, this);
g2.drawImage(picImage2, 527,530, this);
g2.drawImage(picImage2, 350,530, this);
//line number far back
g2.drawImage(picImage2, 605,610, this);
g2.drawImage(picImage2, 95,610, this);
g2.drawImage(picImage2, 445,610, this);
g2.drawImage(picImage2, 275,610, this);
//line number three far front
g2.drawImage(picImage2, 450,447, this);
g2.drawImage(picImage2, 270,447, this);
g2.drawImage(picImage2, 100,447, this);
g2.drawImage(picImage2, 610,447, this);
paint=true;
}
x+=sizeOfbox;
}
y+=sizeOfbox;
}
}
}//END OF PROGRAM
No comments:
Post a Comment