• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using swing for board game.

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi.

I am making an old traditional board game played on a standard 64 squares square board. The game is not so well known (yet ! ;o)
but my question is about strategy for inputting moves. I have made japplet with 64 jbuttons in square. what is a good strategy for captuaring
square location ? I am thinking of making my own class which has a jbutton and two numbers describing row and column, but this seems inelegant
and not so object oriented. What is good way ?
THANKS !!
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's what I did for a chess game -- extended JButton to add my own data including row,col. It worked out fine.
You'll also be able to add in which piece if any is on that button/square, what color the square is, etc. if that's the way you want to go.
Hmmm. Or perhaps that should all be contained in a 'SquareData' class referenced by each Button.

What does the rest of our community have to say about this?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A class extending JButton is one possibility. I might go for a class extending JPanel that adds one JButton to its content pane. Both approaches are feasible, though.
 
Michael Emnon
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok. thanks for replies.

I went ahead and made my own button. now, this button has different states and i give it an icon depending on its state (like fx this could be a rook icon if i was making chess game)
I have implemented a MouseListener and I listen for MouseClicked. Everything works ok except i get a "flickering" when buttons appearances are changed. this seems to be beacause
when just pressing and keeping the mouse button down, the default lightblue color of my button derived from JButton appears. I have overridden the mousePressed() method to do nothing, but this doesnt help. Any pointers ? Also a thin square appears around my icon when a button has just been pressed, i tried setFocusable(false) but no change. That swing library is huge !!
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post the part of your code where you are switching icons? Are you using setIcon() and setPressedIcon()?
Also check out JButton#setFocusPainted() instead of setFocusable()
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic