cheers
//Pieces Class
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
public class Pieces extends JComponent{
ArrayList A;
int k[][];
int x;
int y;
Color color;
public Pieces(int cx, int cy, Color Piececolor)
{
this.x = cx;
this.y = cy;
this.color = Piececolor;
A = new ArrayList();
}
public void paint(Graphics g)
{
int mWidth = getWidth();
g.setColor(Color.red);
for(int i = 0; i <g.hashCode();i++){
g.fillOval(0, 1, mWidth/8, mWidth/8); //THE PIECES
g.fillOval(0, 2, mWidth/8, mWidth/8);
g.fillOval(0, 3, mWidth/8, mWidth/8);
g.fillOval(0, 4, mWidth/8, mWidth/8);
g.fillOval(0, 5, mWidth/8, mWidth/8);
g.fillOval(0, 6, mWidth/8, mWidth/8);
g.fillOval(0, 7, mWidth/8, mWidth/8);
g.fillOval(0, 8, mWidth/8, mWidth/8);
A.add(g);
}
}
}
//Board Class
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import javax.swing.JComponent;
public class Board extends JComponent {
int k = 0;
int row;
int col;
public Board(int x, int y)
{
this.row = x;
this.col = y;
}
/*...........................................................................*/
void drawColor()
{
k = (k + 1) % 2;
}
public void paint(Graphics g)
{
int mWidth = getWidth();
int kHeight = getHeight();
for (int m = 0; m <= row; m++)
{
g.drawLine(0, m * 60, col * 60, m * 60);
for (int s = 0; s <= col; s++)
{
g.drawLine(s * 60, 0, s * 60, row * 60);
}
/*...........................................................................*/
for (int i=0; i<row; i=i+2)
{
for (int j=0; j<col; j=j+2)
{
if(k == 0)
{
g.setColor(Color.black);
this.repaint();
}
if(k==1)
{
g.setColor(Color.orange);
this.repaint();
}
g.fillRect(j*mWidth/8,(1+i)*mWidth/8,mWidth/8,kHeight/8);
g.fillRect((1+j)*mWidth/8,i*mWidth/8,mWidth/8,kHeight/8);
}
}
}
}
}

New Topic/Question
Reply




MultiQuote



|