码迷,mamicode.com
首页 > 其他好文 > 详细

局部匿名内部类

时间:2018-08-01 23:50:00      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:start   OLE   system   ane   ring   ack   java.awt   bee   quit   

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();
    }
}

 

局部匿名内部类

标签:start   OLE   system   ane   ring   ack   java.awt   bee   quit   

原文地址:https://www.cnblogs.com/confusion/p/9404430.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!