Optimization for icons.
This commit is contained in:
parent
545b650013
commit
f809b8c015
1 changed files with 53 additions and 22 deletions
39
Client.java
39
Client.java
|
@ -20,6 +20,7 @@ import javax.swing.border.*;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.*;
|
import java.awt.image.*;
|
||||||
|
import java.io.File;
|
||||||
//import javax.swing.text.html.parser.ParserDelegator;
|
//import javax.swing.text.html.parser.ParserDelegator;
|
||||||
|
|
||||||
public class Client {
|
public class Client {
|
||||||
|
@ -31,6 +32,7 @@ public class Client {
|
||||||
private static final String Columns = "ABCDEFGH";
|
private static final String Columns = "ABCDEFGH";
|
||||||
public static final int BLACK = 0, WHITE = 1;
|
public static final int BLACK = 0, WHITE = 1;
|
||||||
public static String boardoutput = "";
|
public static String boardoutput = "";
|
||||||
|
public String oldBoard = "";
|
||||||
|
|
||||||
public Client() {
|
public Client() {
|
||||||
initializeGui();
|
initializeGui();
|
||||||
|
@ -130,13 +132,13 @@ public class Client {
|
||||||
|
|
||||||
private final void createImages() {
|
private final void createImages() {
|
||||||
try {
|
try {
|
||||||
URL url1 = new URL("http://www.iconsdb.com/icons/preview/black/circle-xxl.png");
|
//URL url1 = new URL("http://www.iconsdb.com/icons/preview/black/circle-xxl.png");
|
||||||
BufferedImage bi = ImageIO.read(url1);
|
BufferedImage bi = ImageIO.read(new File("Resources/black_circle.png"));
|
||||||
Image img = bi.getScaledInstance(64, 64, BufferedImage.SCALE_FAST);
|
Image img = bi.getScaledInstance(64, 64, BufferedImage.SCALE_FAST);
|
||||||
pieceImages[0] = img;
|
pieceImages[0] = img;
|
||||||
|
|
||||||
URL url2 = new URL("http://www.iconsdb.com/icons/preview/white/circle-xxl.png");
|
//URL url2 = new URL("http://www.iconsdb.com/icons/preview/white/circle-xxl.png");
|
||||||
bi = ImageIO.read(url2);
|
bi = ImageIO.read(new File("Resources/white_circle.png"));
|
||||||
img = bi.getScaledInstance(64, 64, BufferedImage.SCALE_FAST);
|
img = bi.getScaledInstance(64, 64, BufferedImage.SCALE_FAST);
|
||||||
pieceImages[1] = img;
|
pieceImages[1] = img;
|
||||||
}
|
}
|
||||||
|
@ -168,6 +170,7 @@ public class Client {
|
||||||
board = TrimBoard(board);
|
board = TrimBoard(board);
|
||||||
int count = 0;
|
int count = 0;
|
||||||
ImageIcon icon = new ImageIcon( new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB));
|
ImageIcon icon = new ImageIcon( new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB));
|
||||||
|
if(oldBoard.equals("")) {
|
||||||
for(int r = 0; r < 8; ++r) {
|
for(int r = 0; r < 8; ++r) {
|
||||||
for(int c = 0; c < 8; c++) {
|
for(int c = 0; c < 8; c++) {
|
||||||
if(board.charAt(count) == 'X') {
|
if(board.charAt(count) == 'X') {
|
||||||
|
@ -191,6 +194,34 @@ public class Client {
|
||||||
else {
|
else {
|
||||||
boardSquares[7][7].setIcon(icon);
|
boardSquares[7][7].setIcon(icon);
|
||||||
}
|
}
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for(int r = 0; r < 8; ++r) {
|
||||||
|
for(int c = 0; c < 8; c++) {
|
||||||
|
if(board.charAt(count) == 'X' && oldBoard.charAt(count) != 'X') {
|
||||||
|
boardSquares[r][c].setIcon(new ImageIcon(pieceImages[0]));
|
||||||
|
}
|
||||||
|
else if(board.charAt(count) == 'O' && oldBoard.charAt(count) != 'O') {
|
||||||
|
boardSquares[r][c].setIcon(new ImageIcon(pieceImages[1]));
|
||||||
|
}
|
||||||
|
else if(board.charAt(count) == '_' && oldBoard.charAt(count) != '_') {
|
||||||
|
boardSquares[r][c].setIcon(icon);
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(board.charAt(count) == 'X') {
|
||||||
|
boardSquares[7][7].setIcon(new ImageIcon(pieceImages[0]));
|
||||||
|
}
|
||||||
|
else if(board.charAt(count) == 'O') {
|
||||||
|
boardSquares[7][7].setIcon(new ImageIcon(pieceImages[1]));
|
||||||
|
}
|
||||||
|
else if(board.charAt(count) == '_' && oldBoard.charAt(count) != '_') {
|
||||||
|
boardSquares[7][7].setIcon(icon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
oldBoard = board;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendLocation(int r, int c) {
|
public void sendLocation(int r, int c) {
|
||||||
|
|
Reference in a new issue