Java tutorial
//package com.java2s; /* * This file is part of ThingsFX. * * ThingsFX is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ThingsFX is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ThingsFX. If not, see <http://www.gnu.org/licenses/>. */ import java.awt.AWTEvent; import java.awt.Container; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; public class Main { private static Field dispatcherField; private static Constructor<?> newLightweightDispatcher; private static Method dispatchMethod; private static Method enableEvents; static void initReflection() { try { // lightweight dispatcher dispatcherField = Container.class.getDeclaredField("dispatcher"); dispatcherField.setAccessible(true); Class<?> dispatcherCls = Class.forName("java.awt.LightweightDispatcher"); newLightweightDispatcher = dispatcherCls.getDeclaredConstructor(new Class[] { Container.class }); newLightweightDispatcher.setAccessible(true); dispatchMethod = dispatcherCls.getDeclaredMethod("dispatchEvent", AWTEvent.class); dispatchMethod.setAccessible(true); enableEvents = dispatcherCls.getDeclaredMethod("enableEvents", new Class[] { long.class }); enableEvents.setAccessible(true); } catch (Exception ex) { System.err.println(ex); InternalError err = new InternalError(); err.initCause(ex); throw err; } } }