【发布时间】:2019-09-30 02:31:13
【问题描述】:
我正在尝试在调用此方法时更改 JButton 上的文本
public Piece select() {
if (this.unit_here != null) {
namedisplay.setText(this.unit_here.name);
}
}
这是该方法所在的完整类
import java.util.ArrayList;
public class BoardWrapper {
private Piece unit_here;
private String terrain_here;
private int terrain_duration;
private int x;
private int y;
public BoardWrapper(int x2, int y2) {
x = x2;
y = y2;
}
public Piece select() {
if (this.unit_here != null) {
namedisplay.setText(this.unit_here.name);
}
}
}
我已将 JButton 声明为 public,但 BoardWrapper 类无法解决它
public JButton namedisplay = new JButton("Unit");
【问题讨论】:
-
BoardWrapper类应该如何知道namedisplay是某个其他类的属性。你需要告诉它。