将Object传递给方法?

时间:2011-04-09 05:21:06

标签: java object registration

public void actionPerformed(ActionEvent actionEvent){ }

除了将ActionEvent的引用传递给actionPerformed方法之外,这一行的详细含义是什么。

2 个答案:

答案 0 :(得分:8)

public void actionPerformed(ActionEvent actionEvent) { }
  • public:可以从任何代码访问方法。
  • void:方法不返回任何内容。
  • actionPerformed:方法名称。
  • (:您开始指定参数列表。
  • ActionEvent:参数类型#1。
  • actionEvent:参数#1的名称。
  • ):您已完成指定参数列表。
  • { }:方法无法执行任何操作。

答案 1 :(得分:4)

此方法是ActionListener接口的一部分。

public class Listener implements ActionListener{

public static void main(String[] args) {
    Listener listener = new Listener();
    Button button = new Button();
    button.addActionListener(listener);
}

public void actionPerformed(ActionEvent e) {
    throw new UnsupportedOperationException("Not supported yet.");
}

}

当用户按下按钮时,将调用Listener类的方法actionPerformed。

相关问题