In the code base, we inherited the use of MediaTracker always performed locally in every block of code.
new MediaTracker(new Canvas()); mediatracker.addImage(i, 1); try { mediatracker.waitForAll(); } catch (InterruptedException e) { } mediatracker.removeImage(i);
Having decided that this was inefficient, I eventually replaced it with a static instance and method:
final static protected MediaTracker mediatracker = new MediaTracker(new Canvas()); static protected void checkImageIsReady(Image i) { mediatracker.addImage(i, 1); try { mediatracker.waitForAll(); } catch (InterruptedException e) { } mediatracker.removeImage(i); }
So far, there have been no negative consequences.
There is another possible approach - to bind MediaTracker to each component (usually to a frame or JFrame), which is strongly implied as the approach that the documentation constructor should use.
I have 2 questions:
source share