• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

How do I target a specific square when I draw this board?

 
Greenhorn
Posts: 8
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a few questions, I wasn't really thinking when I wanted to paint images onto the screen.
How would I make an array recognize each square on this board?
Say I hovered over each individual square, how would I have it highlight?
 
Rancher
Posts: 823
19
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lawrence,

There are basically 2 options with several variations on each one:

1 - do it properly with Object Oriented Code
 here you make tiles and place them, the board is then made up of Tiles and a boarder.  You make a mouse listener and add it to each of the Tiles.  The mouse listener tells the tiles where the pointer is located and the Tile that has been placed where the mouse listener highlights itself and the ones that are not where the pointer is, unhighlights themselves.

2 - you do more of the functional programming model and implement a mouse listener.  The mouse listener sets a highlight region (Tile), according to your mouse location (use some math to calculate the (X, Y) and Width Height for the rectangle) and when the screen is repainted, then only the set hightlight region is highlighted.

Les
 
Lawrence Anon
Greenhorn
Posts: 8
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So would an array still be the best approach to target the specific tile? Sorry i'm still very new to Java, this language is very vast but It's really fun.
 
Les Morgan
Rancher
Posts: 823
19
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lawrence,

Yes.  I generally use an array for keeping track of the Tiles in my games.  For a flat world, checker boards and etc, a 2D array.  If you have more dimensionallity, then an array with appropriate dimensions to fit your needs.

Here is something you are going to be faced with very soon--you may need more than 1 board to play: the state you are in the start of your turn, and  one to many more to calculate movements.

Les
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!