getting the right text from a button in netbeans

前端 未结 1 1009
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-27 13:29
 public class tCalculator implements ActionListener{
   //private JTextField resultText;
    public void Calculator(){
        btn1.addActionListener(this);
        btn2         


        
1条回答
  •  南方客
    南方客 (楼主)
    2021-01-27 14:14

    public void actionPerformed(ActionEvent evt) {
    
            Object source = evt.getSource();
            if (source instanceof JButton){
                JButton but = (JButton) source;
                String text = but.getText();  //do what you want with the text
            }
    }}
    

    0 讨论(0)
提交回复
热议问题