views:

57

answers:

3

I understand that the title might not be descriptive enough, but I'm making a magic square game in Java and basically, I'm trying to replicate user input as found in the sudoku game here: http://www.websudoku.com/.

What I have is a n x n grid of Buttons (not JButton) as the board and what I want the user to be able to do is when the user clicks on one of the buttons, similar to the game above, it allows the user to type in his guess in the button itself instead of popping up a dialog box with an input field of some sort.

I don't know where to start, I am a beginner in Java (not very beginner, but my knowledge with the various Java APIs is very limited), so I'm trying to find out if this would be possible and if it is, how would I go about doing it? Thanks for any help.

+1  A: 

It sounds like instead of a grid of buttons, what you really want is an editable table. You could actually use a button as TableCellRenderer and a textfield as TableCellEditor.

Michael Borgwardt
thank you for both your replies. I did not think about the board in that way at all. I will look into editable table as well. btw, what do u mean the gui design wont work the way the user expects it to? I thought the gui for the sudoku game was very nifty.
@stash211: I think what the other poster meant was that people expect buttons to be clickable, but not to be editable. They might click and then not know what to do, unless you give a very obvious visual clue that the user is now expected to input text.
Michael Borgwardt
+1  A: 
aioobe
A: 

I didn't know if this belonged in comments or answers, but I am posting this as an extension to the previous question. Thank you, both of you, for your help.

I have basically achieved what I set out to do with the program. But now, I want to make it better by having it operate in a multithreaded way. Do any of you have any suggestions as to what aspect of such a magic square program could be delegated to separate threads.

As of now, what the program does is this: prompt the user for the square size > build n x n grid and when user clicks a start button, it starts timing the user. while the user inputs a new entry, the board constantly updates the totals on each row, column and diagonal and updates the appropriate boxes. Finally, when the check for a successful magic square board turns out true, it disables all the textfields and lets the user start a new game or exit.

Once again, while I have programmed in Java for a while, my knowledge is very limited and right now, I want to understand how simple programs like these, while they work well on a single thread, can be built in a multithreaded way.

Lastly, I was checking the Memory used when I run my program (basically looking through task manager in windows, under javaw.exe) and for a grid of 19 x 19, it says about 19000K. Is this too much or about right and if its too much, how can I reduce it?

Thank you greatly for any help.