JTextField, JLabel 에서 text 변경 이벤트 처리하기
프로그래밍/java 2023. 2. 26. 22:58반응형
JLabel : PropertyChangeListener
JTextField : DocumentListener
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
public class TestClass {
JLabel mLabel = new JLabel("TEST");
JTextField mTextField = new JTextField("TEST");
TestClass() {
mLabel.addPropertyChangeListener(new MyChangeListener());
mTextField.getDocument().addDocumentListener(new MyDocumentListener());
}
private class MyChangeListener implements PropertyChangeListener {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if ("text".equals(evt.getPropertyName())) {
}
}
}
private class MyDocumentListener implements DocumentListener {
@Override
public void insertUpdate(DocumentEvent e) {
}
@Override
public void removeUpdate(DocumentEvent e) {
}
@Override
public void changedUpdate(DocumentEvent e) {
}
}
}
반응형