简体   繁体   English

具有自动移动JButton的多线程滑动拼图解算器

[英]Multithreading with automatically moving JButtons for Sliding Puzzle Solver

I created a sliding puzzle program using java. 我使用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 . 然后,我继续实现滑动拼图解算器程序。问题是,当我单击“播放结果”按钮时,该程序将自动将有效方块滑动到目标状态,例如n-puzzle-solver.appspot.com I created this game using JButtons with two dimensional arrays like this(btnTiles[0][0]). 我使用具有这样的二维数组的JButtons(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. 如果可以的话,请教我一个例子或给我一个自动移动JButton的多线程链接。

You may able to leverage the approach shown here , which paces the timing on a thread owned by an instance of javax.swing.Timer . 您可能可以利用此处显示的方法,该方法可以加快javax.swing.Timer实例所拥有的线程的计时。 The example moves all the tiles at each interval, but you can just move one in the List . 该示例以每个间隔移动所有磁贴,但是您可以在List移动一个。

图片

automatically moving JButtons. 自动移动JButton。

wrong way to do it - leave the buttons alone, just change the icons (swap with blank) 这样做的方法有误-不用理会按钮,只需更改图标(将其替换为空白)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM