I created a sliding puzzle program using java. And then, I continued to implement sliding puzzle solver program.The problem is that when I click "play the result" button, the program is to automatically slide valid squares to goal state like this n-puzzle-solver.appspot.com. I created this game using JButtons with two dimensional arrays like this(btnTiles[0][0]). Can I implement it with Multithreading? If I can, please teach me an example or give me a link for multithreading with automatically moving JButtons.
Asked
Active
Viewed 541 times
0

Andrew Thompson
- 168,117
- 40
- 217
- 433

user1814453
- 9
- 1
-
1*"Can I implement it with Multithreading?"* Noone can say that, but you. *"If I can, please teach me an example"* SO is not a code factory. *"or give me a link for multithreading"* See [Concurrency](http://docs.oracle.com/javase/tutorial/essential/concurrency/) *"with automatically moving JButtons"* LOL - Nothing like being specific about what you want. ;) – Andrew Thompson Jan 06 '13 at 03:12
-
1Take a look at [Concurremcy in Swing](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html) for starters – MadProgrammer Jan 06 '13 at 03:43
-
Dear Sir, I see forums are not code factories. I tried to get this. But I can't. So I asked for you some advice for my difficulty. I am sorry for my non specific question.Please forgive me. Thank you for your advice and study link. – user1814453 Jan 06 '13 at 03:52
-
[For Example](http://stackoverflow.com/a/10837751/1057230) – nIcE cOw Jan 06 '13 at 04:08
-
I always believe single threaded applications work better, I.e You would have a single thread which moves and repaints the buttons etc. Because imagine 1 or 2 buttons moving on mutlithreading thats great now as that number increases slower PCs will cry! where as single thread would produce better results. There are many advantages and disadvantages to multithreading i.e Thread creation and destruction overhead etc, so unless you really need it multithreaded stick with a single thread to control all movements repaints etc just like our own Event Dispatch Thread does with our Swing UIs. – David Kroukamp Jan 06 '13 at 08:05
2 Answers
4
automatically moving JButtons.
wrong way to do it - leave the buttons alone, just change the icons (swap with blank)

Michael Dunn
- 818
- 5
- 3
-
1+1 for the better approach; there's a related example [here](http://stackoverflow.com/a/12228640/230513). – trashgod Jan 06 '13 at 03:48