2011-01-14 6 views
0
public void movePiece(JLabel destination){ 
    JLabel currentPiece = piece[oldIndex[0]][oldIndex[1]]; 
    destination = currentPiece; 
    currentPiece.setVisible(false); 
    destination.repaint(); 
    currentPiece.repaint(); 
} 

현재 이동 방법. 텍스트가 "전송"될 JLabel을 취하고, JLabel get은 텍스트를 가져올 JLabel에 대한 참조입니다. 누구 한테 아이디어있어? 이 방법은 효과가 없으며 어떻게 보이는지 알 수 있습니다. JLabel의 2 "Trololo" : JLabel의 1한 JLabel의 내용을 다른 JLabel로 전송하는 방법은 무엇입니까?

: 예를 들어

이 경우인지! "안녕하세요"

대상이 2이고, currentPiece가 1이면, I는 다음과 같이 그것을 싶습니다

JLabel의 1 : (거짓) "Trololo".setVisibility JLabel의 2 : "Trololo"

효과적으로 단지 nr. 2의 내용으로 볼 수있다. 1. 님을 삭제하고 싶지 않습니다. 1, 그냥 보이지 않게하십시오.

대상의 내용을 변경하는

답변

3

전화 setText (그들은 같은 객체를 참조하지 않는, 그들은 단지 동일한 텍스트 및 글꼴이) :

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

감사합니다,이 몰랐다 그게 게터들 이었어! –

관련 문제