Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Clojure and Swing

Name: Anonymous 2010-03-05 1:45

Hey /prog/riders, I'm not a LISPer but I'm learning. I was wondering if it were possible to dynamically create a grid of buttons in swing, instead of initializing all of them individually. I was thinking of making a tic-tac-toe game, but I can't work out how to make it work without making nine specific variable buttons.

Name: Anonymous 2010-03-05 6:36

>>1
I don't know if I understand the question correctly but you want to create a clickable tic-tac-toe board in Swing?
Obviously the best practices / most scalable way is to use a GridBagLayout backed by a 2D-Array, each grid/aray square containing an instance of some "Square" class which extends JPanel. In this way you wouldn't really need to specifically instantiate buttons yourself but they would be created inside the Square class as you add squares to your GBL.

If you don't want to do it this way you could just use a custom Graphics and calculate clicked squares based on x,y co-ordinates and use manual line, circle drawing.

The best option however, would be to just write the application using HTML/AJAX and have a horizontally scalable turn-key tic-tac-toe implementation in the cloud.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List