Java tutorial
//package com.java2s; /* * SwingBugUtilities.java * * Created on March 30, 2007, 12:27 AM * * Copyright 2006-2007 Nigel Hughes * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at http://www.apache.org/ * licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.Timer; public class Main { private static Timer timer; public static boolean isTimerListening(ActionListener testListener) { createTimer(); ActionListener[] listeners = timer.getActionListeners(); for (ActionListener candidate : listeners) { if (candidate == testListener) { return true; } } return false; } private static void createTimer() { if (timer != null) { return; } timer = new Timer(20, new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { } }); timer.setDelay(20); timer.setInitialDelay(20); timer.setCoalesce(true); timer.setRepeats(true); timer.start(); } }