0
 public void movePiece(JLabel destination){
  JLabel currentPiece = piece[oldIndex[0]][oldIndex[1]];
  destination = currentPiece;
  currentPiece.setVisible(false);
  destination.repaint();
  currentPiece.repaint();
 }

現在の移動方法。テキストの「転送」先の JLabel を取得します。JLabel は、テキストの取得元である JLabel への参照を取得します。誰でも思いつきましたか?この方法は機能しません。どのように見えるかを示すだけです。

たとえば、次のような場合:

JLabel 1: 「トロロロ」 JLabel 2: 「こんにちは!」

destination が 2 で currentPiece が 1 の場合、次のようにしたいと思います。

JLabel 1: "トロロロ" .setVisibility(false) JLabel 2: "トロロロ"

効果的にnrのみを作成します。2 nr の内容で表示されます。1. nr を削除したくない。1、見えないようにしてください。

(それらは同じオブジェクトを参照しているのではなく、同じテキストとフォントを持っているだけです)

4

1 に答える 1

3

呼び出しsetTextて宛先の内容を変更します。

public void movePiece(JLabel destination){
  JLabel currentPiece = piece[oldIndex[0]][oldIndex[1]];
  destination.setText(currentPiece.getText());
  currentPiece.setVisible(false);
}
于 2011-01-14T08:28:12.933 に答える