Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package chess;
- import java.awt.Color;
- import java.awt.Image;
- import java.awt.Point;
- import javax.swing.BorderFactory;
- import javax.swing.Icon;
- import javax.swing.ImageIcon;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- public final class Model
- {
- private int Edge;
- private Colors color;
- private Army army;
- private Icons icon;
- private Points point;
- private Labels label;
- public Model()
- {
- init();
- }
- public Model(int Edge, JPanel panel)
- {
- this.Edge = Edge;
- init();
- setContainer(panel);
- }
- private void init()
- {
- this.Edge = 70;
- army = Army.White;
- color = new Colors();
- icon = new Icons();
- point = new Points();
- label = new Labels();
- }
- public void setEdge(int Edge)
- {
- this.Edge = Edge;
- icon.drawImages();
- label.drawSquares();
- }
- public int getEdge()
- {
- return Edge;
- }
- public void setContainer(JPanel panel)
- {
- label.setContainer(panel);
- }
- public void mouseDown(int x, int y)
- {
- point.mouseDown.x = x / Edge;
- point.mouseDown.y = y / Edge;
- if(point.isNone(point.mouseDown) == true || point.isMyArmy(point.mouseDown) == false) return;
- point.isMouseDown = true;
- point.mouseDownImg.x = x - point.mouseDown.x * Edge;
- point.mouseDownImg.y = y - point.mouseDown.y * Edge;
- Point location = label.squares[point.mouseDown.x][point.mouseDown.y].getLocation();
- Color color = label.squares[point.mouseDown.x][point.mouseDown.y].getBackground();
- String name = label.squares[point.mouseDown.x][point.mouseDown.y].getName();
- Icon icon = label.squares[point.mouseDown.x][point.mouseDown.y].getIcon();
- label.set6Properties(label.squareCur, location, true, false, color, name, icon);
- label.set3Properties(label.squares[point.mouseDown.x][point.mouseDown.y], this.color.Movable, Army.None.sName(), null);
- location.x = point.mouseDown.x;
- location.y = point.mouseDown.y;
- point.movable(name, location);
- this.color.movable();
- }
- public void mouseMove(int x, int y)
- {
- if(point.isMouseDown == false)
- {
- return;
- }
- //label.squareCur.setBorder(null);
- label.squareCur.setLocation(x - point.mouseDownImg.x, y - point.mouseDownImg.y);
- }
- public void mouseUp(int x, int y)
- {
- if(point.isMouseDown == false)
- {
- return;
- }
- point.isMouseDown = false;
- label.squareCur.setVisible(false);
- point.mouseUp.x = x / Edge;
- point.mouseUp.y = y / Edge;
- //safeMyKing();
- color.autoLight();
- }
- protected enum Army
- {
- White("White"),
- Dark("Dark"),
- None("None");
- private String army;
- private Army(String army)
- {
- this.army = army;
- }
- public String sName()
- {
- return army;
- }
- public String sArmy(String army)
- {
- if(army.contains(White.sName())) return White.sName();
- if(army.contains(Dark.sName())) return Dark.sName();
- return None.sName();
- }
- }
- protected enum Name
- {
- None("None"),
- WhiteKing("WhiteKing"),
- WhiteQueen("WhiteQueen"),
- WhiteBishop("WhiteBishop"),
- WhiteKnight("WhiteKnight"),
- WhiteRook("WhiteRook"),
- WhitePawn("WhitePawn"),
- DarkKing("DarkKing"),
- DarkQueen("DarkQueen"),
- DarkBishop("DarkBishop"),
- DarkKnight("DarkKnight"),
- DarkRook("DarkRook"),
- DarkPawn("DarkPawn");
- private String name;
- private Name(String name)
- {
- this.name = name;
- }
- public String sName()
- {
- return name;
- }
- }
- public final class Points
- {
- public int movableNumber;
- public Point[] movable;
- public boolean isMouseDown;
- public Point mouseDown;
- public Point mouseDownImg;
- public Point mouseUp;
- public Point lastWhite1;
- public Point lastWhite2;
- public Point lastDark1;
- public Point lastDark2;
- public Points()
- {
- init();
- }
- private void init()
- {
- isMouseDown = false;
- movableNumber = 30;
- movable = new Point[movableNumber];
- int i;
- for(i = 0; i < movableNumber; i++)
- {
- movable[i] = new Point();
- }
- resetMovable();
- mouseDown = new Point();
- mouseDown.x = -1;
- mouseDown.y = -1;
- mouseUp = new Point();
- mouseUp.x = -1;
- mouseUp.y = -1;
- mouseDownImg = new Point();
- mouseDownImg.x = -1;
- mouseDownImg.y = -1;
- lastWhite1 = new Point();
- lastWhite1.x = -1;
- lastWhite1.y = -1;
- lastWhite2 = new Point();
- lastWhite2.x = -1;
- lastWhite2.y = -1;
- lastDark1 = new Point();
- lastDark1.x = -1;
- lastDark1.y = -1;
- lastDark2 = new Point();
- lastDark2.x = -1;
- lastDark2.y = -1;
- }
- public void movable(String name, Point pNow)
- {
- if(name == Model.Name.WhiteKing.sName() || name == Model.Name.DarkKing.sName()) king(pNow);
- else if(name == Model.Name.WhiteQueen.sName() || name == Model.Name.DarkQueen.sName()) queen(pNow);
- else if(name == Model.Name.WhiteBishop.sName() || name == Model.Name.DarkBishop.sName()) bishop(pNow, 0);
- else if(name == Model.Name.WhiteKnight.sName() || name == Model.Name.DarkKnight.sName()) knight(pNow);
- else if(name == Model.Name.WhiteRook.sName() || name == Model.Name.DarkRook.sName()) rook(pNow, 0);
- else if(name == Model.Name.WhitePawn.sName() || name == Model.Name.DarkPawn.sName()) pawn(pNow);
- }
- public void resetMovable()
- {
- int i;
- for(i = 0; i < movableNumber; i++)
- {
- movable[i].x = -1;
- movable[i].y = -1;
- }
- }
- public void safeMyArmy()
- {
- int i;
- for(i = 0; i < movableNumber; i++)
- {
- if(isMyArmy(movable[i]) == true)
- {
- movable[i].x = -1;
- movable[i].y = -1;
- }
- }
- }
- public boolean isSafe(Point pCheck)
- {
- return isSafe(pCheck.x, pCheck.y);
- }
- public boolean isSafe(int x, int y)
- {
- if(x < 0 || x > 7 || y < 0 || y > 7) return false;
- return true;
- }
- public boolean isMovable(Point pCheck)
- {
- int i;
- for(i = 0; i < movableNumber; i++)
- {
- if(pCheck.x == movable[i].x && pCheck.y == movable[i].y)
- {
- return true;
- }
- }
- return false;
- }
- public boolean isAttacked(Point pCheck)
- {
- if(isSafe(pCheck) == true)
- {
- if(isNone(pCheck) == false && isMyArmy(pCheck) == false)
- {
- return true;
- }
- }
- return false;
- }
- public boolean isMyArmy(Point pCheck)
- {
- if(isSafe(pCheck) == false) return false;
- if(army.sArmy(label.squares[pCheck.x][pCheck.y].getName()) == army.sName()) return true;
- return false;
- }
- public boolean isNone(Point pCheck)
- {
- return isNone(pCheck.x, pCheck.y);
- }
- public boolean isNone(int x, int y)
- {
- // isSafe = false => None
- if(point.isSafe(x, y) == false) return true;
- if(army.sArmy(label.squares[x][y].getName()) == Model.Army.None.sName())
- {
- return true;
- }
- return false;
- }
- private void verticalHigh(Point pNow)
- {
- }
- private void verticalLow(Point pNow)
- {
- }
- private void horizontalLeft(Point pNow)
- {
- }
- private void horizontalRight(Point pNow)
- {
- }
- // Diagonal Main: \
- private void diagonalMainHigh(Point pNow)
- {
- }
- private void diagonalMainLow(Point pNow)
- {
- }
- // Diagonal Mirror: /
- private void diagonalMirrorHigh(Point pNow)
- {
- }
- private void diagonalMirrorLow(Point pNow)
- {
- }
- private void king(Point pNow)
- {
- movableNumber = 8;
- movable[0].x = pNow.x - 1;
- movable[0].y = pNow.y - 1;
- movable[1].x = pNow.x;
- movable[1].y = pNow.y - 1;
- movable[2].x = pNow.x + 1;
- movable[2].y = pNow.y - 1;
- movable[3].x = pNow.x + 1;
- movable[3].y = pNow.y;
- movable[4].x = pNow.x + 1;
- movable[4].y = pNow.y + 1;
- movable[5].x = pNow.x;
- movable[5].y = pNow.y + 1;
- movable[6].x = pNow.x - 1;
- movable[6].y = pNow.y + 1;
- movable[7].x = pNow.x - 1;
- movable[7].y = pNow.y;
- safeMyArmy();
- }
- private void castling(Point pNow)
- {
- }
- private void queen(Point pNow)
- {
- rook(pNow, 0);
- bishop(pNow, movableNumber);
- }
- private void rook(Point pNow, int index)
- {
- int x;
- int y;
- int k = index;
- for(x = pNow.x; x >= 0; x--)
- {
- movable[k].x = x;
- movable[k].y = pNow.y;
- if(isNone(movable[k]) == false) break;
- k = k + 1;
- }
- if(isMyArmy(movable[k]) == false) k = k + 1;
- for(x = pNow.x + 1; x < 8; x++)
- {
- movable[k].x = x;
- movable[k].y = pNow.y;
- if(isNone(movable[k]) == false) break;
- k = k + 1;
- }
- if(isMyArmy(movable[k]) == false) k = k + 1;
- for(y = pNow.y; y >= 0; y--)
- {
- movable[k].x = pNow.x;
- movable[k].y = y;
- if(isNone(movable[k]) == false) break;
- k = k + 1;
- }
- if(isMyArmy(movable[k]) == false) k = k + 1;
- for(y = pNow.y + 1; y < 8; y++)
- {
- movable[k].x = pNow.x;
- movable[k].y = y;
- if(isNone(movable[k]) == false) break;
- k = k + 1;
- }
- if(isMyArmy(movable[k]) == false) k = k + 1;
- movable[k].x = -1;
- movable[k].y = -1;
- movableNumber = k;
- safeMyArmy();
- }
- private void bishop(Point pNow, int index)
- {
- int x = pNow.x;
- int y = pNow.y;
- int k = index;
- while(true)
- {
- x = x - 1;
- y = y + 1;
- movable[k].x = x;
- movable[k].y = y;
- if(isSafe(x, y) == false || isNone(movable[k]) == false) break;
- k = k + 1;
- }
- if(isMyArmy(movable[k]) == false) k = k + 1;
- x = pNow.x;
- y = pNow.y;
- while(true)
- {
- x = x + 1;
- y = y - 1;
- movable[k].x = x;
- movable[k].y = y;
- if(isSafe(x, y) == false || isNone(movable[k]) == false) break;
- k = k + 1;
- }
- if(isMyArmy(movable[k]) == false) k = k + 1;
- x = pNow.x;
- y = pNow.y;
- while(true)
- {
- x = x - 1;
- y = y - 1;
- movable[k].x = x;
- movable[k].y = y;
- if(isSafe(x, y) == false || isNone(movable[k]) == false) break;
- k = k + 1;
- }
- if(isMyArmy(point.movable[k]) == false) k = k + 1;
- x = pNow.x;
- y = pNow.y;
- while(true)
- {
- x = x + 1;
- y = y + 1;
- movable[k].x = x;
- movable[k].y = y;
- if(isSafe(x, y) == false || isNone(movable[k]) == false) break;
- k = k + 1;
- }
- if(point.isMyArmy(movable[k]) == false) k = k + 1;
- movable[k].x = -1;
- movable[k].y = -1;
- movableNumber = k;
- safeMyArmy();
- }
- private void knight(Point pNow)
- {
- movableNumber = 8;
- movable[0].x = pNow.x + 1;
- movable[0].y = pNow.y - 2;
- movable[1].x = pNow.x + 2;
- movable[1].y = pNow.y - 1;
- movable[2].x = pNow.x + 2;
- movable[2].y = pNow.y + 1;
- movable[3].x = pNow.x + 1;
- movable[3].y = pNow.y + 2;
- movable[4].x = pNow.x - 1;
- movable[4].y = pNow.y + 2;
- movable[5].x = pNow.x - 2;
- movable[5].y = pNow.y + 1;
- movable[6].x = pNow.x - 2;
- movable[6].y = pNow.y - 1;
- movable[7].x = pNow.x - 1;
- movable[7].y = pNow.y - 2;
- safeMyArmy();
- }
- private void pawn(Point pNow)
- {
- movableNumber = 4;
- int space1 = 0;
- int space2 = 0;
- if(label.squareCur.getName() == Model.Name.WhitePawn.sName())
- {
- space1 = 1;
- if(mouseDown.y == 6) space2 = 2;
- }
- else if(label.squareCur.getName() == Model.Name.DarkPawn.sName())
- {
- space1 = -1;
- if(mouseDown.y == 1) space2 = -2;
- }
- movable[0].x = pNow.x;
- movable[0].y = pNow.y - space1;
- if(isNone(movable[0]) == false)
- {
- movable[0].x = -1;
- movable[0].y = -1;
- movable[3].x = -1;
- movable[3].y = -1;
- }
- else
- {
- movable[3].x = pNow.x;
- movable[3].y = pNow.y - space2;
- if(isNone(movable[3]) == false)
- {
- movable[3].x = -1;
- movable[3].y = -1;
- }
- }
- movable[1].x = pNow.x - space1;
- movable[1].y = pNow.y - space1;
- if(isNone(movable[1]) == true)
- {
- movable[1].x = -1;
- movable[1].y = -1;
- }
- movable[2].x = pNow.x + space1;
- movable[2].y = pNow.y - space1;
- if(isNone(movable[2]) == true)
- {
- movable[2].x = -1;
- movable[2].y = -1;
- }
- safeMyArmy();
- }
- }
- public final class Labels
- {
- public JLabel[][] squares;
- public JLabel squareCur;
- public Labels()
- {
- init();
- }
- private void init()
- {
- squareCur = new JLabel();
- squares = new JLabel[8][8];
- int x;
- int y;
- for(y = 0; y < 8; y++)
- {
- for(x = 0; x < 8; x++)
- {
- squares[x][y] = new JLabel();
- }
- }
- drawSquares();
- }
- public void drawSquares()
- {
- int x = 0;
- int y = 0;
- Point location = new Point();
- location.x = x;
- location.y = y;
- set8Properties(squareCur, false, Edge, location, true, true, Name.None.sName(), null, null);
- for(y = 0; y < 8; y++)
- {
- for(x = 0; x < 8; x++)
- {
- location.x = x * Edge;
- location.y = y * Edge;
- set8Properties(squares[x][y], true, Edge, location, true, true, Name.None.sName(), color.get(x, y), null);
- }
- }
- // White chess Properties
- set2Properties(squares[0][7], Name.WhiteRook.sName(), icon.WhiteRook);
- set2Properties(squares[1][7], Name.WhiteKnight.sName(), icon.WhiteKnight);
- set2Properties(squares[2][7], Name.WhiteBishop.sName(), icon.WhiteBishop);
- set2Properties(squares[3][7], Name.WhiteQueen.sName(), icon.WhiteQueen);
- set2Properties(squares[4][7], Name.WhiteKing.sName(), icon.WhiteKing);
- set2Properties(squares[5][7], Name.WhiteBishop.sName(), icon.WhiteBishop);
- set2Properties(squares[6][7], Name.WhiteKnight.sName(), icon.WhiteKnight);
- set2Properties(squares[7][7], Name.WhiteRook.sName(), icon.WhiteRook);
- for(x = 0; x < 8; x++)
- {
- set2Properties(squares[x][6], Name.WhitePawn.sName(), icon.WhitePawn);
- }
- // Dark chess Properties
- set2Properties(squares[0][0], Name.DarkRook.sName(), icon.DarkRook);
- set2Properties(squares[1][0], Name.DarkKnight.sName(), icon.DarkKnight);
- set2Properties(squares[2][0], Name.DarkBishop.sName(), icon.DarkBishop);
- set2Properties(squares[3][0], Name.DarkQueen.sName(), icon.DarkQueen);
- set2Properties(squares[4][0], Name.DarkKing.sName(), icon.DarkKing);
- set2Properties(squares[5][0], Name.DarkBishop.sName(), icon.DarkBishop);
- set2Properties(squares[6][0], Name.DarkKnight.sName(), icon.DarkKnight);
- set2Properties(squares[7][0], Name.DarkRook.sName(), icon.DarkRook);
- for(x = 0; x < 8; x++)
- {
- set2Properties(squares[x][1], Name.DarkPawn.sName(), icon.DarkPawn);
- }
- }
- public void set8Properties(JLabel label, boolean opaque, int size, Point location, boolean border, boolean visible, String name, Color color, Icon icon)
- {
- label.setOpaque(opaque);
- label.setSize(size, size);
- set6Properties(label, location, border, visible, color, name, icon);
- }
- public void set6Properties(JLabel label, Point location, boolean visible, boolean border, Color color, String name, Icon icon)
- {
- label.setLocation(location);
- if(border == true) label.setBorder(BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
- else label.setBorder(null);
- set3Properties(label, color, name, icon);
- label.setVisible(visible);
- }
- public void set3Properties(JLabel label, Color color, String name,Icon icon)
- {
- label.setBackground(color);
- set2Properties(label, name, icon);
- }
- public void set2Properties(JLabel label, String name, Icon icon)
- {
- label.setName(name);
- label.setIcon(icon);
- }
- public void setContainer(JPanel container)
- {
- if(container == null) return;
- try
- {
- int x;
- int y;
- for(y = 0; y < 8; y++)
- {
- for(x = 0; x < 8; x++)
- {
- container.add(label.squares[x][y]);
- }
- }
- container.add(label.squareCur);
- container.setComponentZOrder(label.squareCur, 0);
- container.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
- container.setPreferredSize(new java.awt.Dimension(Edge * 8, Edge * 8));
- // group layout
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(container);
- container.setLayout(layout);
- } catch(Exception e) {}
- }
- }
- public class Colors
- {
- public Color Default = null;
- public Color White = Color.LIGHT_GRAY;
- public Color Dark = Color.GRAY;
- public Color Movable = new Color(0, 176, 240);
- public Color Attacked = new Color(50, 200, 50);
- public Color WhiteWhite = Color.YELLOW;
- public Color WhiteDark = Color.ORANGE;
- public Color DarkWhite = Color.PINK;
- public Color DarkDark = Color.MAGENTA;
- public Color get(int x, int y)
- {
- if((x + y) % 2 == 0) return White;
- return Dark;
- }
- public Color get(int x, int y, Color white, Color dark)
- {
- if((x + y) % 2 == 0) return white;
- return dark;
- }
- public void movable()
- {
- Point pMove = new Point();
- int i;
- for(i = 0; i < point.movableNumber; i++)
- {
- pMove.x = point.movable[i].x;
- pMove.y = point.movable[i].y;
- if(point.isSafe(point.movable[i]) == false) continue;
- if(point.isAttacked(pMove) == true) label.squares[pMove.x][pMove.y].setBackground(color.Attacked);
- else label.squares[pMove.x][pMove.y].setBackground(color.Movable);
- }
- }
- public void autoLight()
- {
- int x;
- int y;
- int i;
- for(i = 0; i < point.movableNumber; i++)
- {
- x = point.movable[i].x;
- y = point.movable[i].y;
- if(point.isSafe(point.movable[i]) == false) continue;
- label.squares[x][y].setBackground(color.get(x, y));
- }
- undo4Last();
- if(point.isMovable(point.mouseUp) == false)
- {
- point.mouseUp.x = point.mouseDown.x;
- point.mouseUp.y = point.mouseDown.y;
- }
- label.set3Properties(label.squares[point.mouseUp.x][point.mouseUp.y], label.squareCur.getBackground(), label.squareCur.getName(), label.squareCur.getIcon());
- point.resetMovable();
- if(point.mouseDown.x == point.mouseUp.x && point.mouseDown.y == point.mouseUp.y)
- {
- return;
- }
- if(army == Army.White)
- {
- army = Army.Dark;
- compute(color.WhiteWhite, color.WhiteDark, point.lastWhite1, point.lastWhite2, point.lastDark1, point.lastDark2);
- }
- else if(army == Army.Dark)
- {
- army = Army.White;
- compute(color.DarkWhite, color.DarkDark, point.lastDark1, point.lastDark2, point.lastWhite1, point.lastWhite2);
- }
- }
- private void undo4Last()
- {
- int x = point.lastWhite1.x;
- int y = point.lastWhite1.y;
- if(point.isSafe(x, y) == true)
- {
- label.squares[x][y].setBackground(color.get(x, y, color.WhiteWhite, color.WhiteDark));
- }
- x = point.lastDark1.x;
- y = point.lastDark1.y;
- if(point.isSafe(x, y) == true)
- {
- label.squares[x][y].setBackground(color.get(x, y, color.DarkWhite, color.DarkDark));
- }
- x = point.lastWhite2.x;
- y = point.lastWhite2.y;
- if(point.isSafe(x, y) == true)
- {
- label.squares[x][y].setBackground(color.get(x, y, color.WhiteWhite, color.WhiteDark));
- }
- x = point.lastDark2.x;
- y = point.lastDark2.y;
- if(point.isSafe(x, y) == true)
- {
- label.squares[x][y].setBackground(color.get(x, y, color.DarkWhite, color.DarkDark));
- }
- }
- private void compute(java.awt.Color white, java.awt.Color dark, Point me1, Point me2, Point rival1, Point rival2)
- {
- boolean flag = true;
- if(point.isSafe(me1) == false) flag = false;
- if(me1.x == rival2.x && me1.y == rival2.y) flag = false;
- if(flag == true)
- {
- label.squares[me1.x][me1.y].setBackground(color.get(me1.x, me1.y));
- }
- flag = true;
- if(point.isSafe(rival1) == false || point.isSafe(rival2) == false) flag = false;
- if(point.mouseUp.x != rival2.x || point.mouseUp.y != rival2.y) flag = false;
- if(flag == true)
- {
- label.squares[rival1.x][rival1.y].setBackground(color.get(rival1.x, rival1.y));
- label.squares[rival2.x][rival2.y].setBackground(color.get(rival2.x, rival2.y));
- rival1.x = -1;
- rival1.y = -1;
- rival2.x = -1;
- rival2.y = -1;
- }
- flag = true;
- if(point.isSafe(me2) == false) flag = false;
- if(me2.x == rival2.x && me2.y == rival2.y) flag = false;
- if(flag == true)
- {
- label.squares[me2.x][me2.y].setBackground(color.get(me2.x, me2.y));
- }
- if(point.isSafe(point.mouseDown) == true)
- {
- label.squares[point.mouseDown.x][point.mouseDown.y].setBackground(color.get(point.mouseDown.x, point.mouseDown.y, white, dark));
- }
- if(point.isSafe(point.mouseUp) == true)
- {
- label.squares[point.mouseUp.x][point.mouseUp.y].setBackground(color.get(point.mouseUp.x, point.mouseUp.y, white, dark));
- }
- me1.x = point.mouseDown.x;
- me1.y = point.mouseDown.y;
- me2.x = point.mouseUp.x;
- me2.y = point.mouseUp.y;
- }
- }
- public final class Icons
- {
- public ImageIcon WhiteKing;
- public ImageIcon WhiteQueen;
- public ImageIcon WhiteBishop;
- public ImageIcon WhiteKnight;
- public ImageIcon WhiteRook;
- public ImageIcon WhitePawn;
- public ImageIcon DarkKing;
- public ImageIcon DarkQueen;
- public ImageIcon DarkBishop;
- public ImageIcon DarkKnight;
- public ImageIcon DarkRook;
- public ImageIcon DarkPawn;
- public Icons()
- {
- init();
- }
- private void init()
- {
- WhiteKing = new ImageIcon();
- WhiteQueen = new ImageIcon();
- WhiteBishop = new ImageIcon();
- WhiteKnight = new ImageIcon();
- WhiteRook = new ImageIcon();
- WhitePawn = new ImageIcon();
- DarkKing = new ImageIcon();
- DarkQueen = new ImageIcon();
- DarkBishop = new ImageIcon();
- DarkKnight = new ImageIcon();
- DarkRook = new ImageIcon();
- DarkPawn = new ImageIcon();
- drawImages();
- }
- public void drawImages()
- {
- String path = "E:\\ChessImage\\alpha\\";
- WhiteKing.setImage(newImage(path +"WhiteKing.png", Edge, Edge));
- WhiteQueen.setImage(newImage(path +"WhiteQueen.png", Edge, Edge));
- WhiteBishop.setImage(newImage(path +"WhiteBishop.png", Edge, Edge));
- WhiteKnight.setImage(newImage(path +"WhiteKnight.png", Edge, Edge));
- WhiteRook.setImage(newImage(path +"WhiteRook.png", Edge, Edge));
- WhitePawn.setImage(newImage(path +"WhitePawn.png", Edge, Edge));
- DarkKing.setImage(newImage(path +"DarkKing.png", Edge, Edge));
- DarkQueen.setImage(newImage(path +"DarkQueen.png", Edge, Edge));
- DarkBishop.setImage(newImage(path +"DarkBishop.png", Edge, Edge));
- DarkKnight.setImage(newImage(path +"DarkKnight.png", Edge, Edge));
- DarkRook.setImage(newImage(path +"DarkRook.png", Edge, Edge));
- DarkPawn.setImage(newImage(path +"DarkPawn.png", Edge, Edge));
- }
- private Image newImage(String path, int width, int height)
- {
- Image image = new ImageIcon(path).getImage().getScaledInstance(width , height, Image.SCALE_SMOOTH);
- return image;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement