Java tutorial
//package com.java2s; /* * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ import java.util.Collections; import java.util.Map; import java.util.WeakHashMap; import java.applet.Applet; import java.awt.Container; import java.awt.Window; public class Main { private static final Map<Container, Boolean> vsyncedMap = Collections .synchronizedMap(new WeakHashMap<Container, Boolean>()); /** * Sets vsyncRequested state for the {@code rootContainer}. If * {@code isRequested} is {@code true} then vsynced * {@code BufferStrategy} is enabled for this {@code rootContainer}. * * Note: requesting vsynced painting does not guarantee one. The outcome * depends on current RepaintManager's RepaintManager.PaintManager * and on the capabilities of the graphics hardware/software and what not. * * @param rootContainer topmost container. Should be either {@code Window} * or {@code Applet} * @param isRequested the value to set vsyncRequested state to */ public static void setVsyncRequested(Container rootContainer, boolean isRequested) { assert (rootContainer instanceof Applet) || (rootContainer instanceof Window); if (isRequested) { vsyncedMap.put(rootContainer, Boolean.TRUE); } else { vsyncedMap.remove(rootContainer); } } }