gpt4 book ai didi

java - 我尝试在 JButton 上使用 .getName,但它返回 null,但是当我执行 toString 时,它会返回所有正确的属性?

转载 作者:行者123 更新时间:2023-12-01 16:02:21 25 4
gpt4 key购买 nike

来源:javax.swing.JButton[,571,647,80x80,alignmentX=0.0,alignmentY=0.5,border=com.apple.laf.AquaButtonBorder$Toggle@1380cf2a,flags=288,maximumSize=java.awt.Dimension[宽度=80,高度=80],minimumSize=java.awt.Dimension[宽度=80,高度=80],preferredSize=java.awt.Dimension[宽度=80,高度=80],defaultIcon=文件:/Users/andreaks/Desktop/PreEntregaiDomino/build/classes/imagenes/A23.png,disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[顶部=0,左侧=2,底部=0,右侧=2],paintBorder=true,paintFocus= true,pressedIcon=,rolloverEnabled=false,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=,defaultCapable=true]

名称:空

我使用的代码是

private void JBsetseleccionadActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Object boton = evt.getSource();
JButton este= (JButton) boton;

seleccionado = este;
System.out.println("SOURCE " + boton.toString());
System.out.println("NAME " + este.getName());
}

有什么想法吗?

最佳答案

尝试如下:

String text = ((JButton) e.getSource()).getText();

顺便说一句,这样的代码的更好模式是:

private JButton button;
button = new JButton("Button");
button.addActionListener(new BListener());
private class BListener implements ActionListener{
public void actionPerformed(ActionEvent e){
if(e.getSource() == button){
//code for when the JButton button is pushed
}
}
}

关于java - 我尝试在 JButton 上使用 .getName,但它返回 null,但是当我执行 toString 时,它会返回所有正确的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3508095/

25 4 0
文章推荐: perl - 使用 perl 将\x3c/div\x3e 转换为
文章推荐: ios - 旋转 MTLTexture
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com