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 javax.imageio.ImageIO;
|
||||
import java.awt.image.*;
|
||||
import java.io.File;
|
||||
//import javax.swing.text.html.parser.ParserDelegator;
|
||||
|
||||
public class Client {
|
||||
|
@ -31,6 +32,7 @@ public class Client {
|
|||
private static final String Columns = "ABCDEFGH";
|
||||
public static final int BLACK = 0, WHITE = 1;
|
||||
public static String boardoutput = "";
|
||||
public String oldBoard = "";
|
||||
|
||||
public Client() {
|
||||
initializeGui();
|
||||
|
@ -130,13 +132,13 @@ public class Client {
|
|||
|
||||
private final void createImages() {
|
||||
try {
|
||||
URL url1 = new URL("http://www.iconsdb.com/icons/preview/black/circle-xxl.png");
|
||||
BufferedImage bi = ImageIO.read(url1);
|
||||
//URL url1 = new URL("http://www.iconsdb.com/icons/preview/black/circle-xxl.png");
|
||||
BufferedImage bi = ImageIO.read(new File("Resources/black_circle.png"));
|
||||
Image img = bi.getScaledInstance(64, 64, BufferedImage.SCALE_FAST);
|
||||
pieceImages[0] = img;
|
||||
|
||||
URL url2 = new URL("http://www.iconsdb.com/icons/preview/white/circle-xxl.png");
|
||||
bi = ImageIO.read(url2);
|
||||
//URL url2 = new URL("http://www.iconsdb.com/icons/preview/white/circle-xxl.png");
|
||||
bi = ImageIO.read(new File("Resources/white_circle.png"));
|
||||
img = bi.getScaledInstance(64, 64, BufferedImage.SCALE_FAST);
|
||||
pieceImages[1] = img;
|
||||
}
|
||||
|
@ -168,6 +170,7 @@ public class Client {
|
|||
board = TrimBoard(board);
|
||||
int count = 0;
|
||||
ImageIcon icon = new ImageIcon( new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB));
|
||||
if(oldBoard.equals("")) {
|
||||
for(int r = 0; r < 8; ++r) {
|
||||
for(int c = 0; c < 8; c++) {
|
||||
if(board.charAt(count) == 'X') {
|
||||
|
@ -191,6 +194,34 @@ public class Client {
|
|||
else {
|
||||
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) {
|
||||
|
|
Reference in a new issue