-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGhostPiece.java
More file actions
39 lines (31 loc) · 1.03 KB
/
GhostPiece.java
File metadata and controls
39 lines (31 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
public class GhostPiece extends JButton implements ActionListener {
private Square currSquare;
private Checkers game;
public GhostPiece(Square currSquare, Checkers game) {
this.currSquare = currSquare;
this.game = game;
this.setBorderPainted(false);
this.setContentAreaFilled(false);
this.setPreferredSize(new Dimension(50, 50));
this.addActionListener(this);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.WHITE);
g.drawOval(4, 2, 40, 40);
}
// when this ghost piece is clicked on, move the current selected piece to the square that this ghost piece is in
@Override
public void actionPerformed(ActionEvent arg0) {
Piece selectedPiece = game.getSelectedPieceFromCurrPlayer();
if(selectedPiece != null) {
selectedPiece.move(currSquare);
}
}
}