Commit f2b5d1a6 authored by 9611046's avatar 9611046

documentation for Square class

parent db8d2b79
...@@ -18,6 +18,11 @@ public class Square extends JButton { ...@@ -18,6 +18,11 @@ public class Square extends JButton {
private JLabel image; private JLabel image;
private boolean possibleSquare = false; private boolean possibleSquare = false;
/**
*
* @param x x coordinate of square
* @param y y coordinate of square
*/
public Square(int x, int y){ public Square(int x, int y){
this.x=x; this.x=x;
this.y = y; this.y = y;
...@@ -25,6 +30,10 @@ public class Square extends JButton { ...@@ -25,6 +30,10 @@ public class Square extends JButton {
} }
/**
*
* @param piece put a piece on a chess square
*/
public void setPiece(Piece piece) { public void setPiece(Piece piece) {
this.piece = piece; this.piece = piece;
hasPiece = true; hasPiece = true;
...@@ -33,32 +42,58 @@ public class Square extends JButton { ...@@ -33,32 +42,58 @@ public class Square extends JButton {
this.add(image); this.add(image);
} }
/**
* selects a square by redrawing its line border
*/
public void selectSquare() public void selectSquare()
{ {
this.setBorder(BorderFactory.createLineBorder(Color.red,6)); this.setBorder(BorderFactory.createLineBorder(Color.red,6));
this.isSelected=true; this.isSelected=true;
} }
/**
* deselects a square by deleting its red border line
*/
public void cancleSelection(){ public void cancleSelection(){
this.isSelected=true; this.isSelected=false;
this.setBorder(null); this.setBorder(null);
} }
/**
* makes a square possible for moving a piece by making its border line green
*/
public void makePossible(){ public void makePossible(){
this.setBorder(BorderFactory.createLineBorder(Color.green,6)); this.setBorder(BorderFactory.createLineBorder(Color.green,6));
this.possibleSquare = true; this.possibleSquare = true;
} }
/**
* removes a piece of a square
*/
public void removePiece(){ public void removePiece(){
this.piece = null; this.piece = null;
this.remove(image); this.remove(image);
} }
/**
*
* @return true if this square has a piece
*/
public boolean hasPiece() { public boolean hasPiece() {
return hasPiece; return hasPiece;
} }
/**
* @return true if square is possible for moving a piece
*/
public boolean isPossibleSquare() { public boolean isPossibleSquare() {
return possibleSquare; return possibleSquare;
} }
/**
*
* @return the piece of a square
*/
public Piece getPiece(){ public Piece getPiece(){
return piece; return piece;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment