This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Colourful arrays!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Colourful arrays!!" Watch "Colourful arrays!!" New topic

Colourful arrays!!

Mike Smike
Ranch Hand

Joined: Aug 25, 2004
Posts: 33
Hey everyone,

I've created a game which consists of a Game class and an Interface class. The interface is simply a 10 x 10 grid of squares, each holding a value. In the Game class, there is an int array of [100] which stores all the values. In the Interface class, there is a JTextField array of [100] which prints out the values in the Game class array.

My problem is this. There are two players playing the game. Each has a different colour. I want each player's square to have the background colour of that player. How can I do this?

I know how to set the background colour of a text box, but how can I specify only to do this when a square belongs to Player 1 or Player 2? Is there a way to build the Game class array, with int values, and have each value associated with a Player? So two objects per item in the array? That way I suppose I could set the colour using comparsion operators. Is there an easier way?

Thanks loads for any help you can give me! I need to have this done by tomorrow

Thanks guys

Mike Smike
Ranch Hand

Joined: Aug 25, 2004
Posts: 33
Hmm well I seemed to have solved the probelm. I just created an object which held both a value and a player object and created an array of them. Not extremely elegant but probably not a bad solution.


I agree. Here's the link:
subject: Colourful arrays!!
Similar Threads
OO design question?
array of array help
general irksome headbanging problem!
More design questions - referencing a variable or object from an argument?
synchronization.. and threads !!!