Guest User

Untitled

a guest
Jan 12th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import java.awt.Color;
  5. import javax.swing.border.*;
  6. import java.util.ArrayList;
  7. import java.awt.image.BufferedImage;
  8. import javax.imageio.ImageIO;
  9. //import javax.swing.ImageIcon;
  10. import java.io.*;
  11.  
  12. class Chessboard extends JFrame{
  13.  
  14. private Pieces[][] pieces;
  15. private JPanel panel;
  16. private ImageIcon BlackRook,WhiteRook,BlackQueen,WhiteQueen,BlackPawn,WhitePawn,BlackKing,WhiteKing,BlackKnight,WhiteKnight,BlackBishop,WhiteBishop;
  17. private JLabel addBlackRook;
  18. private static ArrayList<Pieces> White;
  19. private static ArrayList<Pieces> Black;
  20. public static Border blackBorder = new LineBorder(Color.black);
  21. public static void main(String[] args){
  22. Chessboard a = new Chessboard();
  23. a.setVisible(true);
  24. }
  25.  
  26. public Chessboard() {
  27. this.pieces = new Pieces[8][8];
  28. this.panel = new JPanel(new GridLayout(8, 8));
  29. Black = new ArrayList<Pieces>();
  30. White = new ArrayList<Pieces>();
  31. boolean backGround = false;
  32. for (int row = 0; row < pieces.length; row++){
  33. for(int col = 0; col < pieces[row].length; col++){
  34. Pieces newpiece = new Pieces(row, col, 2);
  35. if (row == 0){
  36. if (col == 0 || col == 7){
  37. BlackRook = new ImageIcon(new ImageIcon("BlackRook.png").getImage().getScaledInstance(100,100, Image.SCALE_SMOOTH));
  38. addBlackRook = new JLabel(BlackRook);
  39. add(addBlackRook);
  40.  
  41. }
  42. /*else{
  43. WhiteRook = new ImageIcon(new ImageIcon("./Pieces/WhiteRook.png").getImage().getScaledInstance(100, 100, Image.SCALE_SMOOTH));
  44. }*/
  45. Black.add(newpiece);
  46. }
  47. pieces[row][col] = newpiece;
  48. newpiece.setOpaque(true);
  49. newpiece.setBorder(blackBorder);
  50. if (col == 0){
  51. backGround = !backGround;
  52. }
  53. if (backGround){
  54. newpiece.setBackground(Color.white);
  55. backGround = false;
  56. }
  57. else{
  58. newpiece.setBackground(Color.red);
  59. backGround = true;
  60. }
  61. panel.add(newpiece);
  62. }
  63. }
  64. guiSetup();
  65. }
  66.  
  67. public void guiSetup(){
  68. this.setTitle("CHESS");
  69. this.setLocation(100,100);
  70. this.add(panel);
  71. this.setSize(800, 800);
  72. this.setVisible(true);
  73. this.setDefaultCloseOperation(EXIT_ON_CLOSE);
  74. }}
Add Comment
Please, Sign In to add comment