首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何访问复合toString类中的ChangeListener中的ChangeListener()方法?

如何访问复合toString类中的ChangeListener中的ChangeListener()方法?
EN

Stack Overflow用户
提问于 2015-05-04 02:19:01
回答 1查看 107关注 0票数 0

我有一个JButton作文类,我有一个要发送给不同类中的JLabel的toString。当我打电话给toString时,我得到了这样的信息: javax.swing.DefaultButtonModel@f730d2f

代码语言:javascript
复制
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;

  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-04 02:20:19

使用EmptySpace.this.toString()

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30021677

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档