저는 java에 익숙하지 않고 다음과 같은 문제가 있습니다 : 버튼에 ActionListener를 추가했는데 그 번호에서 액세스하고 싶습니다.하지만 제가했던 것처럼 작동하지 않습니다. 나는 그것에 착수했지만 대답을 찾을 수 없었다. 코드는 이제 다음과 같습니다 : 당신은 액션 청취자의 상단에 마지막으로 텍스트 변수를 선언해야ActionListener에서 Integer를 가져 오는 방법은 무엇입니까?
public class example extends JPanel{
int text;
public example(){
JButton button = new JButton("x");
JTextField textField = new JTextField();
add(textField);
add(button);
ActionListener al = new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
text = Integer.parseInt(textField.getText());
}
}
button.addActionListener(al);
system.out.println(text);
}
}
문제가 있습니다. – Dungnbhut
예, 작동하지만 정수를 ActionListener 외부에서 가져올 수 있습니까? – Andy
수정 사항을 확인하십시오. Java 기본을 살펴 봐야한다고 생각합니다. – npk