Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
chess
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
9611046
chess
Commits
db8d2b79
Commit
db8d2b79
authored
May 16, 2019
by
9611046
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
made Square class (a chess board has 64 Squares)
parent
754fbcf6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
0 deletions
+65
-0
Square.java
src/game/Square.java
+65
-0
No files found.
src/game/Square.java
0 → 100644
View file @
db8d2b79
package
game
;
import
pieces.Piece
;
import
javax.swing.*
;
import
java.awt.*
;
/**
* A chess board has 64 squares on a square might exist a piece or not
*/
public
class
Square
extends
JButton
{
int
x
;
int
y
;
private
Piece
piece
;
private
boolean
isSelected
=
false
;
private
boolean
hasPiece
=
false
;
private
JLabel
image
;
private
boolean
possibleSquare
=
false
;
public
Square
(
int
x
,
int
y
){
this
.
x
=
x
;
this
.
y
=
y
;
}
public
void
setPiece
(
Piece
piece
)
{
this
.
piece
=
piece
;
hasPiece
=
true
;
ImageIcon
img
=
new
ImageIcon
(
this
.
getClass
().
getResource
(
piece
.
getImage
()));
image
=
new
JLabel
(
img
);
this
.
add
(
image
);
}
public
void
selectSquare
()
{
this
.
setBorder
(
BorderFactory
.
createLineBorder
(
Color
.
red
,
6
));
this
.
isSelected
=
true
;
}
public
void
cancleSelection
(){
this
.
isSelected
=
true
;
this
.
setBorder
(
null
);
}
public
void
makePossible
(){
this
.
setBorder
(
BorderFactory
.
createLineBorder
(
Color
.
green
,
6
));
this
.
possibleSquare
=
true
;
}
public
void
removePiece
(){
this
.
piece
=
null
;
this
.
remove
(
image
);
}
public
boolean
hasPiece
()
{
return
hasPiece
;
}
public
boolean
isPossibleSquare
()
{
return
possibleSquare
;
}
public
Piece
getPiece
(){
return
piece
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment