Subscribe in a reader

Chess Java Code Help Needed?

mrperu16 asked:


Now im using the following code to make a chess game in Java, however im getting an error message, anyone know what im doing wrong?

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.Cursor;
import java.awt.GridLayout;
import java.awt.event.InputEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.TreeMap;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import java.awt.Dimension;

public class ChessGame extends JFrame {

private static final long serialVersionUID = 1L;

private JPanel jContentPane = null;

private JPanel jPanel = null;

private JToolBar tlbMain = null;

private JLabel lblCells[] = new JLabel[64];

private String jPieces[][] = new String[8][8]; // @jve:decl-index=0:

private JButton btnNewGame = null;

private JLabel lblStatus = null;

private int heldX, heldY, heldI = -1;

// Map the full names of the pieces to their codenames (wRook, wQueen, etc.)
private Map pieceName = new TreeMap(); // @jve:decl-index=0:

private JLabel lblCurrPlayer = null;

// Stores the current player’s move – we can easily match it against
// the first character of the pieces array
private char currPlayer = ‘ ‘;

private JButton btnUndo = null;

private int[][] moves = new int[10][6];

private String movedPieces[] = new String[10];

private int currMove = 0;

/**
* This is the default constructor
*/
public ChessGame() {
super();
initialize();
buildBoard();
}

/**
* This method initializes btnUndo
*
* @return javax.swing.JButton
*/
private JButton getBtnUndo() {
if (btnUndo == null) {
btnUndo = new JButton();
btnUndo.setText(“Undo”);
btnUndo.setEnabled(false);
btnUndo.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseReleased(java.awt.event.MouseEvent e) {
undoMove();
}
});
}
return btnUndo;
}

public static void main( String args[] ) {
new ChessGame().setVisible(true);
}

/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(671, 555);
this.setContentPane(getJContentPane());
this.setTitle(“Basic Chess”);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
}

/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJPanel(), BorderLayout.CENTER);
jContentPane.add(getTlbMain(), BorderLayout.NORTH);
}
return jContentPane;
}

/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
GridLayout gridLayout = new GridLayout();
gridLayout.setRows(8);
gridLayout.setHgap(5);
gridLayout.setVgap(5);
gridLayout.setColumns(8);
jPanel = new JPanel();
jPanel.setLayout(gridLayout);
//buildBoard();
}
return jPanel;
}

private void newGame()
{
resetBoard();
resetPieces();
}

private void resetPieces()
{
jPieces = new String[8][8];
jPieces[0][0] = “bRook”;
jPieces[0][1] = “bKnight”;
jPieces[0][2] = “bBishop”;
jPieces[0][3] = “bKing”;
jPieces[0][4] = “bQueen”;
i get this error message

Exception in thread “main” java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(ImageIO.java:1322)
at ChessGame.PaintPiece(ChessGame.java:190)
at ChessGame.RepaintPieces(ChessGame.java:215)
at ChessGame.resetPieces(ChessGame.java:180)
at ChessGame.buildBoard(ChessGame.java:352)
at ChessGame.(ChessGame.java:66)
at ChessGame.main(ChessGame.java:89)

Website content

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

3 Responses to “Chess Java Code Help Needed?”

  1. Kansieo.com Says:

    Create a video blog

    ouch…i hurt my eyes looking at that lol. What error message are you getting?

  2. Website content Says:

    Create a video blog…instantly.

    your code is incomplete. if we cannot see line 190 we cannot help you. post the entire code.

  3. chess pieces Says:

    Caffeinated Content

    It looks to me that Yahoo! Answers has only posted part of your program. You can post the whole thing, with formatting in the following forum:

    Java Forum:

    My best guess is that the method called: “PaintPiece()” is trying to paint a null piece. Perhaps there is no piece because it’s an empty square.