public void movePiece(JLabel destination){
JLabel currentPiece = piece[oldIndex[0]][oldIndex[1]];
destination = currentPiece;
currentPiece.setVisible(false);
destination.repaint();
currentPiece.repaint();
}
当前的 move 方法。它获取文本要“传输”到的 JLabel,JLabel 获取对从中获取文本的 JLabel 的引用。有人知道吗?该方法不起作用,只是让您了解它的外观。
例如,如果是这种情况:
JLabel 1:“Trololo” JLabel 2:“你好!”
如果目的地是 2 并且 currentPiece 是 1,我希望它看起来像这样:
JLabel 1:“Trololo”.setVisibility(false) JLabel 2:“Trololo”
有效地只生产nr。 2 可见 nr 的内容。 1. 不想删除nr。 1、保持不可见即可。
(它们不是指同一个对象,它们只是具有相同的文本和字体)
最佳答案
调用setText
来更改目的地的内容:
public void movePiece(JLabel destination){
JLabel currentPiece = piece[oldIndex[0]][oldIndex[1]];
destination.setText(currentPiece.getText());
currentPiece.setVisible(false);
}
关于java - 如何将一个 JLabel 的内容传输到另一个 JLabel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4689125/