繁体   English   中英

将来自JTextField的输入存储在Variable中

[英]Store input from JTextField in Variable

我一直在尝试使用存储在JTextField中的输入进行计算,但似乎无法将其实际存储在变量中。 当然,我知道我可以使用.getText(),但是在actionListener之外访问文本存在问题。

          textInput.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){

                    String input = textInput.getText();
                    //How do I get the 'input' variable outside this method? 
               } 
           });

//您在方法内部定义了输入,这就是为什么您不能在方法外部访问的原因。

      String input="";
 textInput.addActionListener(new ActionListener(){
                    public void actionPerformed(ActionEvent e){

                        input = textInput.getText();
                        //How do I get the 'input' variable outside this method? 
                   } 
               });

应用此代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM