/ Published in: Java
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
package mychessgui; import javax.swing.*; import java.awt.*; import javax.swing.border.LineBorder; public class Main { static final char BLACK_PAWN = '\u265F'; static final char BLACK_ROOK = '\u265C'; static final char BLACK_KNIGHT = '\u265E'; static final char BLACK_BISHOP = '\u265D'; static final char BLACK_QUEEN = '\u265B'; static final char BLACK_KING = '\u265A'; static final char WHITE_PAWN = '\u2659'; static final char WHITE_ROOK = '\u2656'; static final char WHITE_KNIGHT = '\u2658'; static final char WHITE_BISHOP = '\u2657'; static final char WHITE_QUEEN = '\u2655'; static final char WHITE_KING = '\u2654'; /** * @ShreyHaria args the command line arguments */ GUI gui = new GUI(); Tile[] board = new Tile[64]; int count = 0; for (int rank = 1; rank <= 8; rank++, count++) { for (char file = 'a'; file <= 'h'; file++) { if ((file + rank) % 2 == 0) { } else { } gui.mainframe.add(board[count].lbl); if (rank == 2) { board[count].lbl.setText("" + WHITE_PAWN); } else if (rank == 7) { board[count].lbl.setText("" + BLACK_PAWN); } else if (rank == 1) { switch (file) { case 'a': case 'h': board[count].lbl.setText("" + WHITE_ROOK); break; case 'b': case 'g': //board[count].lbl.setIcon(WK);/**/ /*heree got it*/// board[count].lbl.set board[count].lbl.setText("" + WHITE_KNIGHT); break; case 'c': case 'f': board[count].lbl.setText("" + WHITE_BISHOP); break; case 'd': board[count].lbl.setText("" + WHITE_QUEEN); break; case 'e': board[count].lbl.setText("" + WHITE_KING); break; } } else if (rank == 8) { switch (file) { case 'a': case 'h': board[count].lbl.setText("" + BLACK_ROOK); break; case 'b': case 'g': board[count].lbl.setText("" + BLACK_KNIGHT); break; case 'c': case 'f': board[count].lbl.setText("" + BLACK_BISHOP); break; case 'd': board[count].lbl.setText("" + BLACK_QUEEN); break; case 'e': board[count].lbl.setText("" + BLACK_KING); break; } } } } gui.mainframe.setVisible(true); } } class GUI { GUI() { mainframe.setSize(700, 700); mainframe.setLayout(grid); } } class Tile { lbl.setFont(unicode); lbl.setText(lblname); lbl.setBackground(tc); lbl.setBorder(border); lbl.setOpaque(true); } }