-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
113 additions
and
23 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package view; | ||
|
||
import java.awt.event.MouseEvent; | ||
import java.awt.event.MouseListener; | ||
|
||
public class BoardEventListener implements MouseListener { | ||
|
||
@Override | ||
public void mouseClicked(MouseEvent e) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void mouseEntered(MouseEvent e) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void mouseExited(MouseEvent e) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void mousePressed(MouseEvent e) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void mouseReleased(MouseEvent e) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,61 @@ | ||
package view; | ||
|
||
import java.awt.Color; | ||
import java.awt.Graphics; | ||
import java.awt.Graphics2D; | ||
import java.awt.RenderingHints; | ||
|
||
import javax.swing.BorderFactory; | ||
import javax.swing.JButton; | ||
import java.awt.*; | ||
import javax.swing.*; | ||
|
||
/** | ||
* Represents a graphical checkers piece on the checkers canvas. | ||
* @author john | ||
* | ||
*/ | ||
public class Checker extends JButton { | ||
|
||
/* The color of the checker */ | ||
private Color color; | ||
|
||
public Checker(Color color) { | ||
super(""); | ||
this.color = color; | ||
initButtonProperties(); | ||
} | ||
|
||
/** | ||
* Initializes the properties of the Checker as a JButton | ||
*/ | ||
private void initButtonProperties() { | ||
/* We want the JButton to actually be completely transparent */ | ||
this.setContentAreaFilled(false); | ||
this.setBorderPainted(false); | ||
this.setFocusable(false); | ||
this.setOpaque(false); | ||
} | ||
|
||
|
||
/** | ||
* Overrides the JButton's painComponent method to paint a circle which | ||
* represents the checkers piece. | ||
*/ | ||
@Override | ||
protected void paintComponent(Graphics g) { | ||
Graphics2D g2 = (Graphics2D) g; | ||
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); | ||
g2.setColor(color); | ||
g2.fillOval(5, 5, getSize().width-10,getSize().height-10); | ||
super.paintComponent(g2); | ||
/* 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); | ||
} | ||
|
||
} |
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