[英]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.