日期:2014-05-20  浏览次数:20697 次

关于java.beans.EventHandler方法的疑问
本帖最后由 Destroy_The_Code 于 2013-03-26 11:48:46 编辑
麻烦大家给些关于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);
  }
}