我想從另一種方法使用這個稱爲「用戶名」的字符串,但我似乎無法弄清楚該怎麼做。從另一種方法調用字符串 - Java
我有這段代碼就在這裏,它指定文本字段的進入到一個變量,但我似乎不能在另一種方法來使用這個變量現在
//Configuring content pane
JFormattedTextField formattedTextField = new JFormattedTextField();
formattedTextField.setBounds(129, 36, 120, 20);
UsernameFrame.getContentPane().add(formattedTextField);
UsernameFrame.setVisible(true);
//Assigning text field entry to variable
String username = formattedTextField.getText();
,我想使用在方法這個變量下面粘貼,但我不知道我錯過了什麼..
public void actionPerformed(ActionEvent e){
if(username.length() < 5){
}
//Execute when the button is pressed
System.out.println("The button has been pressed");
}
這可能是您的幫助球員很簡單的東西,我失蹤了,謝謝。
(完整的代碼)
你可能想要在類中聲明'String username'而不是那個特定的方法。 – yoozer8 2013-03-03 03:05:56