JFrame myframe = new JFrame("My Sample Frame");
JButton mybutton = new JButton("Okay");谁能给我解释一下这部分。
mybutton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
//Assuming that the content here will do something.
}发布于 2011-06-14 21:34:32
关于代码,您到底有哪些不理解的地方?
该代码向该按钮添加一个操作侦听器。单击按钮时,将调用操作侦听器的actionPerformed方法。
请注意,此处使用的是anonymous inner class。
发布于 2011-06-14 22:32:37
这里使用的是匿名内部类。
您已经在技术上实现了ActionListener。当您调用addActionListener时:
mybutton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
//Assuming that the content here will do something.
}您创建了一个匿名类的实例,或者创建了一个实现了没有名称的ActionListener的类。
如需更多信息,请访问 this link .
发布于 2011-06-14 21:34:10
你应该阅读这篇关于writing Event Listeners的教程。
https://stackoverflow.com/questions/6344269
复制相似问题