[英]How do I transfer the contents of one JLabel to another?
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:“ Trololo” JLabel 2:“ Hello!”
如果destination是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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.