局部匿名内部类
Posted confusion
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了局部匿名内部类相关的知识,希望对你有一定的参考价值。
package anonymousInnerClass; import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.Timer; public class AnonymousInnerClassTest { public static void main(String[] args) { TalkingClock clock = new TalkingClock(); clock.start(100,true); JOptionPane.showMessageDialog(null,"Quit Program?"); System.exit(0); } } class TalkingClock{ public void start(int interval, boolean beep) { //Anonymous Inner Class that implements the interface:ActionListener ActionListener listener = new ActionListener() { //need implements the actionPerformed function public void actionPerformed(ActionEvent event) { System.out.println("At the tone,the time is: "+new Date()); if(beep) Toolkit.getDefaultToolkit().beep(); } }; Timer t = new Timer(interval,listener); t.start(); } }
以上是关于局部匿名内部类的主要内容,如果未能解决你的问题,请参考以下文章