Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
CSE-4705-Checkers/src/view/Checker.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
60 lines (50 sloc)
1.44 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package view; | |
import java.awt.*; | |
import javax.swing.*; | |
/** | |
* Represents a graphical checkers piece on the checkers canvas. | |
* @author john | |
* | |
*/ | |
@SuppressWarnings("serial") | |
public class Checker extends JPanel { | |
/* The color of the checker */ | |
private Color color; | |
public Checker(Color color) { | |
super(); | |
this.color = color; | |
initChecker(); | |
} | |
/** | |
* Initializes the properties of the Checker as a JButton | |
*/ | |
private void initChecker() { | |
this.setFocusable(false); | |
this.setOpaque(false); | |
this.setEnabled(false); | |
} | |
/** | |
* Overrides the JButton's painComponent method to paint a circle which | |
* represents the checkers piece. | |
*/ | |
@Override | |
protected void paintComponent(Graphics g) { | |
/* Cast to a 2D graphics object */ | |
Graphics2D g2 = (Graphics2D) g; | |
/* Add some hints from rendering */ | |
RenderingHints hints = new RenderingHints(null); | |
hints.put(RenderingHints.KEY_ANTIALIASING, | |
RenderingHints.VALUE_ANTIALIAS_ON); | |
hints.put(RenderingHints.KEY_INTERPOLATION, | |
RenderingHints.VALUE_INTERPOLATION_BICUBIC); | |
hints.put(RenderingHints.KEY_RENDERING, | |
RenderingHints.VALUE_RENDER_QUALITY); | |
g2.setRenderingHints(hints); | |
/* Set the graphics object's color to the checker's color | |
* and paint an oval which represents the checker. */ | |
g2.setColor(color); | |
g2.fillOval(5, 5, getSize().width-10,getSize().height-10); | |
/* Make a call to the super classes painComponent method */ | |
super.paintComponent(g2); | |
} | |
} |