麻烦大家给些关于EventHandler的方法
create(Class<T> listenerInterface, Object target, String action, String eventPropertyName)
和
create(Class<T> listenerInterface, Object target, String action, String eventPropertyName, String listenerMethodName)
的简单运用实例。我对这两个方法的各种参数作用还不能有实际的理解和体会。
java EventHandler?
------解决方案--------------------
import java.awt.event.ActionListener;
import java.beans.EventHandler;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class MainClass extends JFrame {
JLabel label = new JLabel("Ready...", JLabel.CENTER);
int count;
public MainClass() {
JButton launchButton = new JButton("Launch!");
getContentPane().add(launchButton, "South");
getContentPane().add(label, "Center");
launchButton.addActionListener((ActionListener) EventHandler.create(ActionListener.class, this,
"actionName"));
}
public void actionName() {
label.setText("Launched: " + count++);
}
public static void main(String[] args) {
JFrame frame = new MainClass();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(150, 150);
frame.setVisible(true);
}
}