我有一个JButton作文类,我有一个要发送给不同类中的JLabel的toString。当我打电话给toString时,我得到了这样的信息: javax.swing.DefaultButtonModel@f730d2f
public class EmptySpace{
private JButton button;
protected int x;
protected int y;
protected String name;
public EmptySpace(String text, int x, int y){
this.name = text;
this.x = x;
this.y = y;
button = new JButton(text);
button.getModel().addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
ButtonModel model = (ButtonModel) e.getSource();
if (model.isRollover()) {
Board.toStringText.setText(e.getSource().toString()); //Where toString is called
} else if (model.isPressed()) {
}
}
});
}
public String toString(){ //toString I want to access
return "Name: " + name + " Xcoords: " + x + " Ycoords: " + y;
}
public JButton getButton(){
return button;
}
}发布于 2015-05-04 02:20:19
使用EmptySpace.this.toString()。
https://stackoverflow.com/questions/30021677
复制相似问题