如何将一个 JLabel 的内容传输到另一个 JLabel?
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:“你好!”
如果目的地是 2 并且 currentPiece 是 1,我希望它看起来像这样:
JLabel 1: "Trololo" .setVisibility(false) JLabel 2:“Trololo”
有效地仅生产 nr。 2 可见 nr 的内容。 1. 不想删除nr。 1、保持不可见即可。
(它们不是指同一个对象,只是具有相同的文本和字体)
public void movePiece(JLabel destination){
JLabel currentPiece = piece[oldIndex[0]][oldIndex[1]];
destination = currentPiece;
currentPiece.setVisible(false);
destination.repaint();
currentPiece.repaint();
}
Current method for moving. It takes the JLabel to which the text is to be "transferred", the JLabel get's a reference to the JLabel from which to take the text. Anyone got any idea? The method doesn't work, just gives you an idea of how it's going to look.
For example if this is the case:
JLabel 1: "Trololo"
JLabel 2: "Hello!"
if destination is 2 and currentPiece is 1, I'd like it to look like this:
JLabel 1: "Trololo" .setVisibility(false)
JLabel 2: "Trololo"
Effectively making only nr. 2 visible with the contents of nr. 1.
Don't want to remove nr. 1, just keep it invisible.
(they are not referring to the same object, they just have the same text and font)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调用
setText
来更改目的地的内容:Call
setText
to change the contents of the destination: