<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Latest posts for the topic "Chess woes..."]]></title>
		<link>http://forums.hotjoe.com/posts/list/14.page</link>
		<description><![CDATA[Latest messages posted in the topic "Chess woes..."]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>Chess woes...</title>
				<description><![CDATA[ Hey, guys. I've been trying to program a graphical version of chess in Java. Everything has gone smoothly so far; I have a new game button, the app closes, and I've constructed the chess board. However, I cannot for the life of me figure out how to put the pictures of the pieces on the board. The code I have so far for my Board class is this:<br /> <br /> [code]public class Board extends JPanel implements ImageObserver{<br /> <br /> 	private static final int ROW = 8; <br /> 	private static final int COL = 8; <br /> 	private static final int WIDTH = 600;<br /> 	private static final Dimension SIZE = new Dimension(WIDTH,WIDTH);<br /> 	<br /> 	private static final Color dark = new Color(0x575757);<br /> 	private static final Color lite = new Color(0xE8E8E8);<br /> 	<br /> 	private int board[][] = new int[12][12]; //Internal representation of the board<br /> 	private Image pieces[] = new Image[17];<br /> 	<br /> 	public Board(){<br /> 		setPreferredSize(SIZE);<br /> 		<br /> 		pieces[1] = (new ImageIcon("C:\\Documents and Settings\\WKU Student\\Desktop\\Fall 2009\\Computer Science\\chessPieceImages\\whitePawn.gif")).getImage();<br /> 		pieces[2] = (new ImageIcon("C:\\Documents and Settings\\WKU Student\\Desktop\\Fall 2009\\Computer Science\\chessPieceImages\\whiteKnight.gif")).getImage();<br /> 		pieces[3] = (new ImageIcon("C:\\Documents and Settings\\WKU Student\\Desktop\\Fall 2009\\Computer Science\\chessPieceImages\\whiteBishop.gif")).getImage();<br /> 		pieces[4] = (new ImageIcon("C:\\Documents and Settings\\WKU Student\\Desktop\\Fall 2009\\Computer Science\\chessPieceImages\\whiteCastle.gif")).getImage();<br /> 		pieces[5] = (new ImageIcon("C:\\Documents and Settings\\WKU Student\\Desktop\\Fall 2009\\Computer Science\\chessPieceImages\\whiteQueen.gif")).getImage();<br /> 		pieces[6] = (new ImageIcon("C:\\Documents and Settings\\WKU Student\\Desktop\\Fall 2009\\Computer Science\\chessPieceImages\\whiteKing.gif")).getImage();<br /> 		<br /> 		pieces[11] = (new ImageIcon("C:\\Documents and Settings\\WKU Student\\Desktop\\Fall 2009\\Computer Science\\chessPieceImages\\blackPawn.gif")).getImage();<br /> 		pieces[12] = (new ImageIcon("C:\\Documents and Settings\\WKU Student\\Desktop\\Fall 2009\\Computer Science\\chessPieceImages\\blackKnight.gif")).getImage();<br /> 		pieces[13] = (new ImageIcon("C:\\Documents and Settings\\WKU Student\\Desktop\\Fall 2009\\Computer Science\\chessPieceImages\\blackBishop.gif")).getImage();<br /> 		pieces[14] = (new ImageIcon("C:\\Documents and Settings\\WKU Student\\Desktop\\Fall 2009\\Computer Science\\chessPieceImages\\blackCastle.gif")).getImage();<br /> 		pieces[15] = (new ImageIcon("C:\\Documents and Settings\\WKU Student\\Desktop\\Fall 2009\\Computer Science\\chessPieceImages\\blackQueen.gif")).getImage();<br /> 		pieces[16] = (new ImageIcon("C:\\Documents and Settings\\WKU Student\\Desktop\\Fall 2009\\Computer Science\\chessPieceImages\\blackKing.gif")).getImage();<br /> 	}<br /> 	<br /> 	public void newGame(){<br /> 		<br /> 		//Original board setup<br /> 		int original[][] = {{99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99},<br /> 							{99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99},<br /> 							{99, 99, 24, 22, 23, 25, 26, 23, 22, 24, 99, 99},<br /> 							{99, 99, 21, 21, 21, 21, 21, 21, 21, 21, 99, 99},<br /> 							{99, 99, 00, 00, 00, 00, 00, 00, 00, 00, 99, 99},<br /> 							{99, 99, 00, 00, 00, 00, 00, 00, 00, 00, 99, 99},<br /> 							{99, 99, 00, 00, 00, 00, 00, 00, 00, 00, 99, 99},<br /> 							{99, 99, 00, 00, 00, 00, 00, 00, 00, 00, 99, 99},<br /> 							{99, 99, 11, 11, 11, 11, 11, 11, 11, 11, 99, 99},<br /> 							{99, 99, 14, 12, 13, 15, 16, 13, 12, 14, 99, 99},<br /> 							{99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99},<br /> 							{99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}};<br /> 		<br /> 		//Reset the board<br /> 		for(int row = 0; row &lt; 12; row++)<br /> 			for(int col = 0; col &lt; 12; col++)<br /> 				board[col][row] = original[col][row];<br /> 		<br /> 		//Update the board<br /> 		repaint();<br /> 	}<br /> 	<br /> 	protected void paintComponent(Graphics g){<br /> 		super.paintComponent(g);<br /> 		int panelWidth = getWidth();<br /> 		int panelHeight = getHeight();<br /> 		<br /> 		for(int row = 0; row &lt; ROW; row++){<br /> 			double height = (double) panelHeight / ROW;<br /> 			int y = (int)(height * row);<br /> 			<br /> 			for(int col = 0; col &lt; COL; col++){<br /> 				double width = (double) panelWidth / COL;<br /> 				int x = (int)(width * col);<br /> 				<br /> 				Color c = ((row % 2 == 0) ^ (col % 2 == 0)) ? lite : dark;<br /> 				g.setColor(c);<br /> 				g.fillRect(x, y, (int)width, (int)height);<br /> 				<br /> 				try{<br /> 					g.drawImage(pieces[board[x][y] - 10], x, y, this);<br /> 				} catch(ArrayIndexOutOfBoundsException e){}<br /> 			}<br /> 		}<br /> 	}<br /> 	<br /> 	private static void createAndShowUI(){<br /> 		JFrame frame = new JFrame("Java Chess");<br /> 		frame.getContentPane().add(new Board());<br /> 		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br /> 		frame.pack();<br /> 		frame.setLocationRelativeTo(null);<br /> 		frame.setVisible(true);<br /> 	}<br /> }[/code]<br /> <br /> Does anyone have any ideas on what I'm doing wrong? Or any other ideas on how I can get the images to load properly?]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/649/2444.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/649/2444.page</link>
				<pubDate><![CDATA[Sat, 28 Nov 2009 17:35:53]]> GMT</pubDate>
				<author><![CDATA[ DaGarver]]></author>
			</item>
			<item>
				<title>Re:Chess woes...</title>
				<description><![CDATA[ Do they just not load or what happens?]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/649/2446.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/649/2446.page</link>
				<pubDate><![CDATA[Mon, 30 Nov 2009 12:05:38]]> GMT</pubDate>
				<author><![CDATA[ stdunbar]]></author>
			</item>
	</channel>
</rss>
