さて、私はJavaアプリケーションの作成を通してクラッシュコースをやっており、アクションの実行に問題があります。プログラムは15個のパズルで、一度に1つずつスライドして順番にすべての番号を取得しようとするので、クリックしたユーザーのボードを解決する「自動」モードのオプションが許可されます。だから私のコードは、私が自動ボタンをクリックすると '正方形'(JButtons)のどれも動かないテキストファイルからソリューションを読み込みます。だから私はちょうどプロセスが完全に処理されているかどうかわからないのかどうかはわかりません。私のコードをheres、私は必要な場合はそれ以上のものを供給することができます。私は「自動」ボタンをクリックして、私はそれはそれがあったコードをループしたかどうかを確認するために、画面への出力を印刷して、ボタンのちょうどどれもが通過するたびに移動していないときJavaのActionEventは複数のボタンを移動します
if (e.getSource() == ctrButtons[0]) {
System.out.println("Auto Mode started\n");
Scanner s = null;
try {
s = new Scanner(new BufferedReader(new FileReader("move_list.txt")));
int count = 0;
while (s.hasNext()) {
//Cycle through to move in move_list
if (count != 18) {
s.next();
count+=1;
}
else {
int cur_move = Integer.parseInt(s.next());
count = 0;
/*Use cur_move to move blank space accordingly
*UP------------3
*LEFT----------2
*RIGHT---------1
*DOWN----------0
*/
int zero_index = -1;
for (int j=0; j<jbnButtons.length; j++) {
if (Integer.parseInt(jbnButtons[j].getText()) == 0) {
zero_index = j;
break;
}
}
Point zero = jbnButtons[zero_index].getLocation();
//Check if move is up
if (cur_move == 3) {
Point next = jbnButtons[zero_index-4].getLocation();
jbnButtons[zero_index].setLocation(next);
jbnButtons[zero_index-4].setLocation(zero);
}
//Check if move is left
else if (cur_move == 2) {
Point next = jbnButtons[zero_index-1].getLocation();
jbnButtons[zero_index].setLocation(next);
jbnButtons[zero_index-1].setLocation(zero);
}
//Check if move is right
else if (cur_move == 1) {
Point next = jbnButtons[zero_index+1].getLocation();
jbnButtons[zero_index].setLocation(next);
jbnButtons[zero_index+1].setLocation(zero);
}
//Check if move is down
else {
System.out.println("Current move = 0");
Point next = jbnButtons[zero_index+4].getLocation();
jbnButtons[zero_index].setLocation(next);
jbnButtons[zero_index+4].setLocation(zero);
}
}
}
}
だから私のコードが実行されますループ。何か案は??
@mike:Yep 1+。私はまた、ファイルからのデータの読み込みと、少なくとも2つの方法へのボタンの移動を分けます。そうすれば、各セクションを個別にテストしてデバッグする方がはるかに簡単です。データをArrayListに読み込み、次のメソッドmoveメソッドでArrayListを反復処理します。 –
申し訳ありませんが私はしばらくかかった、私は仕事とこれ以外のすべてのことでこれをテストするために多くの時間を持っていませんでしたが、これは私が探していたものです。私はそれがイベントディスパッチスレッド上で動作することと関係があり、私のActionEventコールが終了するまでGUIが更新されないと考えました – mike