Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron committed Mar 30, 2016
2 parents 2059be3 + cfff108 commit 206281a
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/view/CheckersCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public void initSquares() {
if (i % 2 == 0) {
for (int j = 0; j < BOARD_DIM/2; ++j) {
Square black = new Square(Color.BLACK, i, j*2);
black.add(new GUIPiece(Color.WHITE));
Square red = new Square(Color.RED, i, j*2 + 1);
this.add(black);
blackSquares.add(black);
Expand Down
36 changes: 36 additions & 0 deletions src/view/GUIPiece.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package view;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.JButton;

public class GUIPiece extends JButton {
private Color color;

public GUIPiece(Color color) {
super("");
this.color = color;
this.setContentAreaFilled(false);
this.setBorderPainted(false);
}

protected void paintComponent(Graphics g) {
if (getModel().isArmed()) {
g.setColor(color);
} else {
g.setColor(getBackground());
}
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.fillOval(0, 0, getSize().width,getSize().height-1);
super.paintComponent(g2);
}

}
32 changes: 32 additions & 0 deletions src/view/RoundedBorder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package view;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Insets;

import javax.swing.border.Border;

public class RoundedBorder implements Border {

private int radius;


RoundedBorder(int radius) {
this.radius = radius;
}


public Insets getBorderInsets(Component c) {
return new Insets(this.radius+1, this.radius+1, this.radius+2, this.radius);
}


public boolean isBorderOpaque() {
return true;
}


public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
g.drawRoundRect(x, y, width-2, height-2, radius, radius);
}
}
13 changes: 13 additions & 0 deletions src/view/Square.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;

import javax.swing.JButton;

public class Square extends JButton {
private Color color;
private int row;
private int column;
private GUIPiece piece;

public Square(Color color, int row, int column) {
super("");
this.color = color;
this.setRow(row);
this.setColumn(column);
this.setBackground(color);
this.setLayout(new BorderLayout());
//this.setPreferredSize(new Dimension(100, 100));
}

public int getRow() {
Expand All @@ -33,5 +38,13 @@ public void setColumn(int column) {
this.column = column;
}

public GUIPiece getPiece() {
return piece;
}

public void setPiece(GUIPiece piece) {
this.piece = piece;
}


}

0 comments on commit 206281a

Please sign in to comment.